Tuesday, May 3, 2011

Embed HTML in JavaScript

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?

From stackoverflow

0 comments:

Post a Comment