+ 2

JavaScript line break

document.write(" I am \n learning js"); I wrote this code but line is not breaking why.

27th Jul 2020, 2:02 PM
Adnan Ur Rehman
Adnan Ur Rehman - avatar
2 Answers
+ 8
Try the <br> tag instead of '\n'.
27th Jul 2020, 2:08 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 3
Adnan Ur Rehman document.write(someContent) writes someContent to the document as html markup. That means someContent is treated as html code. So, to put a line break in a html document we need <br/> element.
27th Jul 2020, 2:29 PM
Hanuma Ukkadapu
Hanuma Ukkadapu - avatar