0

How can you to the next line in the output using java script?

24th Feb 2017, 5:44 AM
Roheeet Tamboli
Roheeet Tamboli - avatar
2 Answers
+ 4
When you output some text using JavaScript, you usualy do it in html context... so new line character ( \n ) is interpreted as a simple space ( blank character ) as default behavior ( spaces series are collapsed into once ) and break lines occurs when needed by container. To force a break line, you can insert a <br> tag: many ways are possible for that purpose... document.write('<br>'); document.getElementById('myContainer').innerHTML='<br>'; document.getElementById('myContainer').appendChild(document.createElement('br')); ... and so on ^^ You can also embed your output in a container styled for change default behavior in space handling by html rules, with the css property 'white-space': white-space: normal; /* default behavior */ white-space: nowrap; /* as 'normal', without auto line breaks */ white-space: pre; /* format preserved: number of spaces and line breaks as original content ( default begavior of <pre> html element ) */ white-space: pre-wrap; /* as 'pre', with auto line breaks depending on container size */ white-space: pre-line; /* white spaces collapsed, auto line breaks, and new lines ( \n ) interpreted */
24th Feb 2017, 1:45 PM
visph
visph - avatar
0
thanks man that wad very helpful!
24th Feb 2017, 1:54 PM
Roheeet Tamboli
Roheeet Tamboli - avatar