var html=' <div> <span> hello world</span> </div> '; alert(html);
This will produce an error:”unterminated string literal“. To write multi-line string, you have to append a back slash to each line as follow:
var html='\ <div>\ <span> hello world</span>\ </div>\ '; alert(html);
<div id="mymultilinestring" style="display:none"> <div> <span> hello world</span> </div> </div> <script> var html=document.getElementById("mymultilinestring").innerHTML; alert(html); </script>
i.e, surround the multi-line string with an invisible div element, then get the string thru the innerHTML property of the div element. This way, you do not need to add back slash at the end of each line, but also have the ability of preserving the new line characters within the string.