Forum Moderators: open

Message Too Old, No Replies

multiple lines document.write

         

jonplackett

12:57 pm on Dec 4, 2004 (gmt 0)

10+ Year Member



hi guys.

does anyone know if it's possible to use document.write() to output multiple lines instead of having to put it at the beginning of every new line.

ie.
document.write('line 1')
document.write('line 2')
document.write('line 3')

thanks

Bernard Marx

2:31 pm on Dec 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have a few choices. The code you posted doesn't actually write new lines into the code. To do that you need to use writeln. Since the formatting of the code doesn't make any difference to the result, this doesn't matter.

So how about:

document.write(
'line1'
+'line2'
+'line3'
)

If you really want linebreaks in the code, either:

document.write(
'line1' + '\n'
+'line2' + '\n'
+'line3' + '\n'
)

..or use a single string, and escape the linebreak in the input.

document.write(
'line1\
line2\
line3'
)

This can be fiddly, so it may not be worth it.