Embed HTML in JavaScript

I have a piece of HTML that I would like to add to a document at runtime.

How to embed HTML in a JS file?

var p = document.createElement("div"); p.innerHTML = '<div> MY HTML <some element> </some element> <some element> </some element> </div>' 

The problem is that my HTML is multi-line; how to add newline characters to js string?

+4
source share
1 answer

you can use the backslash character to ignore the end of the line in JavaScript lines.

http://www.componentart.com/BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx

+2
source

All Articles