- 3

\n

why doesn't line break work?!

3rd Aug 2020, 4:51 PM
Ovidiu CATRINA
Ovidiu CATRINA - avatar
10 Respostas
+ 7
May be you can present us a code snippet that shows this issue? Thanks!
3rd Aug 2020, 4:56 PM
Lothar
Lothar - avatar
+ 5
Elaborate your question and mention the language in tags
3rd Aug 2020, 4:54 PM
v@msi😉
v@msi😉 - avatar
+ 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");
3rd Aug 2020, 5:18 PM
Seb TheS
Seb TheS - avatar
+ 3
Context please 😳
3rd Aug 2020, 4:52 PM
Sandra Meyer
Sandra Meyer - avatar
+ 2
Use <br> instead of \n in document.write
3rd Aug 2020, 5:16 PM
v@msi😉
v@msi😉 - avatar
+ 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.
3rd Aug 2020, 5:20 PM
Divya Mohan
Divya Mohan - avatar
+ 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>
4th Aug 2020, 5:11 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
code: document.write("Hello World! \n next line"); output: Hello World! next line
3rd Aug 2020, 5:10 PM
Ovidiu CATRINA
Ovidiu CATRINA - avatar
+ 1
Seb TheS, correct!
3rd Aug 2020, 5:28 PM
Ovidiu CATRINA
Ovidiu CATRINA - avatar
+ 1
Try <br/>
3rd Aug 2020, 7:51 PM
Panda🐼🐼🐼
Panda🐼🐼🐼 - avatar