- 3
\n
why doesn't line break work?!
10 Respostas
+ 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/>