views:

115

answers:

2

I have a chunk of HTML which I'd like to add to a document at run time.

How do I embed the HTML within the 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 multiline; how do I add the newline chars within a JS string?

+2  A: 

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

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

marduk