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?
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?
Share asked Apr 30, 2009 at 17:08 Robin RodricksRobin Rodricks 114k147 gold badges414 silver badges617 bronze badges 3- You don't want the <br/> tags do you? – dirkgently Commented Apr 30, 2009 at 17:11
- 4 Why do you care if your HTML is multiline? The browser will be stripping out the whitespace anyway. – Thomas L Holaday Commented Apr 30, 2009 at 17:12
- 3 @Thomas: Ever tried editing a large chunk of HTML (or anything else for that matter) that is place all on one line. – AnthonyWJones Commented Apr 30, 2009 at 17:19
1 Answer
Reset to default 2you can use backslash character to ignore end of line in JavaScript strings.
http://www.ponentart./BLOGS/jovan/archive/2007/10/17/multiline-strings-in-javascript.aspx
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744819841a4595548.html
评论列表(0条)