Jump to content

Why document.writeln do not set a new line!?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
I make:
document.writeln("here the one text");

document.writeln("and this text must be on new line");

or:

document.writeln("here the one text");

document.innerHTML = "<br>";

document.writeln("and this text must be on new line");
the same situation, it is all only on 1 line!?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
writeln() will create a newline, and a newline is ignored in HTML syntax. You must use writeln to compose a line break as well.

document.writeln("here the one text");
document.writeln("<br>"); 
document.writeln("and this text must be on new line");
Or you could wrap your code in preformatting tags, to expose the newline:

document.writeln("<pre>");
document.writeln("here the one text"); 
document.writeln("and this text must be on new line");
document.writeln("</pre>"); 

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users