The following code:
var str= \"English Comprehension<\\/strong>
JavaScript doesn't allow literal line breaks in strings unless you escape them with \
:
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\/>";
You might look at ES2015+ template literals instead, which use backticks instead of '
or "
and allow literal line breaks:
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\/>`;
But of course, that only works on ES2015-compatible JavaScript engines (or if you transpile).
Note that within a template literal ${...}
has special meaning (allowing you to substitute the result of any expression:
let v = "Ma";
console.log(`Look ${v}, no hands!`); // Look Ma, no hands!
If you want to maintain your data in one block of string, try:
var str= "<strong>English Comprehension</strong>\n\
<br />\n\
<ul>\n\
<li> Synonyms/Antonyms/Word Meaning (Vocabulary)</li>\n\
<li> Complete the Sentence (Grammar)</li>\n\
<li> Spot error/Correct sentence (Grammar/sentence construction)</li>\n\
<li> Sentence Ordering (Comprehension skills)</li>\n\
<li> Questions based on passage (Comprehension skills)</li>\n\
</ul>\n\
<br />";
notice the \n\
at the end of each line.
Remove the newlines, it will work. GOTCHA to keep in mind ;) See it simple works all fine here without newlines: http://jsfiddle.net/87dYh/
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\/>";
alert(str);