+ 1

Why can’t I insert a new line in javascript?

Hi everybody, I just cannot figure out why I can’t use the “\n” character to add a new line. Below is my test code, It should display: Line 1 Line 2 Can someone advise what is wrong?? <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <script type = "text/javascript"> document.write("Line 1 \n") document.write("Line 2") </script> </body> </html> Regards Ben

10th Jul 2019, 4:22 PM
Ben
1 Resposta
+ 2
With document.write, you don't use \n, but <br />: document.write("Line 1 <br />"); document.write("Line 2");
10th Jul 2019, 4:36 PM
Airree
Airree - avatar