I tried making a web page by writing
document.write("This is the first line \n And this is the second");
The desired effect is:
This is the first line
And this is the second
But I get this:
This is the first line And this is the second
I tried writing <br> inside and it worked. But Why writing an escape \n didn’t? Anything I am doing wrong? I am using Firefox.
You are not doing anything wrong. Its just the
\ncharacter is valid in text related elements like, alert() and<textarea>.The
document.write()command writes to the body of the site or the display (in the HTML). Substitute<br>in place of the\nhere since you are writing HTML in the page