- 3
\n
why doesn't line break work?!
10 Answers
+ 7
May be you can present us a code snippet that shows this issue? Thanks!
+ 5
Elaborate your question and mention the language in tags
+ 4
Ovidiu CATRINA Because document.write writes a string as HTML and HTML don't understand \n or it has a certain rule to change multiple chained whitespaces into 1 space.
When you want to display newline in HTML you may use <br />:
document.write("Hello World! <br /> next line");
+ 3
Context please š³
+ 2
Use <br> instead of \n in document.write
+ 2
I think
it don't work if we write
with text that will be part of document .
I have tried it in innerHTML and document.write it didn't woork
But works well in alert and console.
+ 2
To create a line break in JavaScript, use ā<br>ā. With this, we can add more than one line break also.
<html>
Ā Ā <body> Ā
Ā Ā <script> Ā Ā Ā Ā Ā <!-- Ā Ā Ā Ā Ā Ā document.write("Hello World!"); Ā Ā Ā Ā Ā Ā document.write("<br>"); Ā Ā Ā Ā Ā Ā document.write("Demo<br><br>Text!"); Ā Ā Ā Ā Ā //--> Ā Ā Ā </script> Ā Ā </body> </html>
+ 1
code:
document.write("Hello World! \n next line");
output:
Hello World! next line
+ 1
Seb TheS, correct!
+ 1
Try <br/>