Document writeln() Method - Javascript DOM

Javascript examples for DOM:Document writeln

Description

The writeln() method outputs text to document with a newline character after each statement.

Syntax

document.writeln(exp1, exp2, exp3, ...);

Parameter Values

Parameter Description
exp1, exp2, exp3, ... Optional. arguments to be appended to the document in order of occurrence

Return Value:

No return value

The following code shows the difference between write() and writeln():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Note that write() does NOT add a new line after each statement:</p>

<pre>
<script>
document.write("Hello World!");
document.write("Have a nice day!");
</script>/*from  w ww .ja v a2s  .  c  om*/
</pre>

<p>Note that writeln() add a new line after each statement:</p>

<pre>
<script>
document.writeln("Hello World!");
document.writeln("Have a nice day!");
</script>
</pre>

</body>
</html>

Related Tutorials