"This is the first line\nAnd this is the second"
I tried making a web page by writing
document.write("This is the first line\nAnd 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
To add to what JMRKER said, whitespace is handled automatically if it's in the body of your page, but not when used in alert boxes and input elements etc. So all your whitespace characters (spaces, new lines etc.) are treated like a single space until the text needs to wrap to the next line, in which case the whitespace character (whatever it is) is treated like a newline character.
Another example that would show this would be writing several spaces after each other:
alert("Hello foo bar."); // shows several spaces between foo and bar
document.write("Hello foo bar."); // shows only a single space