HTML DOM Document writeln()
More examples below.
Description
Thewriteln() method writes directly to an open (HTML) document stream.
Thewriteln() method is identical to the write() method,with the addition of writing a newline character (U+000A) after each statement.
Warning
Thewriteln() method deletes all existing HTML when used on a loaded document.
Thewriteln() method cannot be used in XHTML or XML.
Syntax
Parameters
| Parameter | Description |
| exp1,... | Optional. The output stream. Multiple arguments are appended to the document in order of occurrence. |
Return Value
| NONE |
The Difference Between write() and writeln()
writeln() adds a newline character after each statement. write() does not.
Example
document.write("Have a nice day!");
document.write("<br>");
document.writeln("Hello World!");
document.writeln("Have a nice day!");
Note
It makes no sense to usewriteln() in HTML.
It is only useful when writing to text documents (type=".txt").
Newline characters are ignored in HTML.
If you want new lines in HTML, you must use paragraphs or <br>:
Examples
document.write("<br>");
document.write("Have a nice day!");
document.write("<p>Have a nice day!</p>");
Browser Support
document.write is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera | IE |
| Yes | Yes | Yes | Yes | Yes | Yes |

