Reputation: 165
Is there a way to add new lines in javascript while printing html? So that the printed html is indented.
document.getElementById("id").innerHTML = "<div class="1"><div class="2">hello</div></div>"
Instead I want to something like this:
document.getElementById("id").innerHTML = "
<div class="1">
<div class="2">
hello
</div>
</div>"
Upvotes: 0
Views: 94
Reputation: 34591
document.getElementById("id").innerHTML =
['<div class="1">',
' <div class="2">',
' hello',
' </div>',
'</div>',
].join('\n');
Or just escape new lines:
document.getElementById("id").innerHTML =
"<div class="1"> \
<div class="2"> \
hello \
</div> \
</div>";
Or the same with jQuery:
$("#id").html(
"<div class="1"> \
<div class="2"> \
hello \
</div> \
</div>");
Upvotes: 1