spanning multiple lines with string text in javascript
Posted: Fri Oct 22, 2010 12:16 pm
javascript breaks strings of text and considers the next line a line of code to interpret, this allows for single line execution after if statements:
instead of a more easily flow read like this (and a semicolon at the end to declare the end of a statement)
beyond that, to get a lot of text to behave as if it were formatted as a long html or php string in javascript, this will not work:
but this will by escaping and marking (\) the newlines to collate or combine in javascript:
*even the first empty line if existant
you may find this useful for template design and quick html to javascript creation of inline scripting. quick. fast. easy.
but not made for use all of the time and to be lazy.
Code: Select all
if(a==b)
document.write("correct answer!")
Code: Select all
if(a==b)
{
document.write("i am easy to read");
}
Code: Select all
var str="
<html>
<body>
testing123
</body>
</html>
";
*even the first empty line if existant
Code: Select all
var str="\
<html>\
<body>
testing123\
<\body>\
<\html>\
";
but not made for use all of the time and to be lazy.