HTML DOM Document writeln() method
- Previous Page write()
- Next Page all[]
- Go to the Previous Level HTML DOM Documents
Definition and usage
writeln()
This method writes directly to the opened (HTML) document stream.
writeln()
This method is the same as the write() method, but adds a newline character after each statement.
Warning
writeln()
This method deletes all existing HTML when used on a loaded document.
writeln()
This method cannot be used with XHTML or XML.
See also:
Syntax
document.writeln(exp1, exp2, exp3, ...)
Parameter
Parameter | Description |
---|---|
exp1, exp2, exp3, ... |
Optional. Output stream. Allows multiple parameters and appends them to the document in the order they appear. |
Return value
None.
Difference between write() and writeln()
writeln() adds a newline character after each statement. write() does not.
Example
document.write("Hello World!"); document.write("Have a nice day!"); document.write("<br>"); document.writeln("Hello World!"); document.writeln("Have a nice day!");
Note
Use in HTML writeln() is meaningless. It is only useful when writing a text document (type=".txt"). Newline characters are ignored in HTML.
If you want to break lines in HTML, you must useParagraphOr <br>
:
Example 1
document.write("Hello World!"); document.write("<br>"); document.write("Have a nice day!");
Example 2
document.write("<p>Hello World!</p>"); document.write("<p>Have a nice day!</p>");
Browser support
All browsers support document.write
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page write()
- Next Page all[]
- Go to the Previous Level HTML DOM Documents