The following code:
var str= \"English Comprehension<\\/strong>
My code was a response.write() where I needed to insert html to be outputted POST SUbmit on a form within an Iframe. When copying my code over from an text editor the carraige return carried over into the code window. Once I deleted my returns and whitespace between tags so that the code looked like a block paragraph that fixed the issue:
("loremIPSUM.<br><br><h2>Title</h2><br>loremIPSUM:<br><br><br><a href='http://url1'>lnk1</a><br><br><a href='http://url2'>loremIPSUMlnk2</a><br><br><a href='http://url3'>loremIPSUM</a><br><br><a href='url4'>IF THE case id is: "</a>"+value)
A good way to concatenate strings in javascript is fallowing:
var stringBuilder = [];
stringBuilder.push("<strong>English Comprehension</strong>");
stringBuilder.push("<br />");
stringBuilder.push("<ul>");
...
var resultString = stringBuilder.join("");
This method faster than
var str = "a"+"b" +"c"
If using multiline string in JavaScript you must use '\' in the end of each line:
var str = "abc\
def\
ghi\
jkl";
Also beware extra whitespace if your code is indented.
I suggest to do it differently... have hidden element with that HTML e.g.
<div id="myHiddenDiv" style="display: none;"><strong>English Comprehension</strong>
<br />
...
</div>
Then simply read its inner HTML:
var str = document.getElementById("myHiddenDiv").innerHTML;
The big advantage is that you won't have to fight your way with literal strings and it's much easier to edit, the downside is that you add another element to the DOM. Your choice. :)
You can't split a string across lines like that in javascript. You could accomplish the same readability by making each line a separate string and concatenating them with the plus sign like so:
var str = "<strong>English Comprehension</strong>"
+ "<br />"
+ "<ul>"
+ "<li>Synonyms/Antonyms/Word Meaning (Vocabulary)</li>"
and so on...
It is not a best practice to write multiline strings in Javascript.
But, you can do that with the \
terminator:
var str= "<strong>English Comprehension<\/strong>\
<br\/>\
<ul>\
<li> Synonyms/Antonyms/Word Meaning (Vocabulary)<\/li>\
<li> Complete the Sentence (Grammar)<\/li>\
<li> Spot error/Correct sentence (Grammar/sentence construction)<\/li>\
<li> Sentence Ordering (Comprehension skills)<\/li>\
<li> Questions based on passage (Comprehension skills)<\/li>\
<\/ul>\
<br\/>";
Note that trailing spaces are part of the string, so it is better to get rid of them, unless they are intentional:
var str= "<strong>English Comprehension<\/strong>\
<br\/>\
<ul>\
<li> Synonyms/Antonyms/Word Meaning (Vocabulary)<\/li>\
<li> Complete the Sentence (Grammar)<\/li>\
<li> Spot error/Correct sentence (Grammar/sentence construction)<\/li>\
<li> Sentence Ordering (Comprehension skills)<\/li>\
<li> Questions based on passage (Comprehension skills)<\/li>\
<\/ul>\
<br\/>";