How to use Document write in JavaScript

This article describe about Document write() Method in JavaScript.
  • 2249

Document write() Method

HTML expressions or JavaScript code to a document written by the write() method.

Syntax

document.write(exp1,exp2,exp3,...)

 

Parameter Description
(exp1,exp2, exp3.....) Optional. What to write to the output stream. Multiple arguments can be listed and they will be appended to the document in order of occurrence

Example

<!DOCTYPE html>

<html>

<body>

<script type="text/javascript">

    document.write("Hello frindes!");

</script>

</body>

</html>

Output

pic17.jpg

Example 2.

<!DOCTYPE html>

<html>

<body>

<script type="text/javascript">

    document.write("<h1>Hello friends!</h1><p>Have a good day!</p>");

</script>

</body>

</html>

 

Output

 

pic18.jpg

 

Note: Difference between write() and writeln() method.

 

Example 3.

 

<!DOCTYPE html>

<html>

<body>

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

<pre>

<script type="text/javascript">

    document.write("Hello friends!");

    document.write("Have a good day!");

</script>

</pre>

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

<pre>

<script type="text/javascript">

    document.writeln("Hello friends!");

    document.writeln("Have a good day!");

</script>

</pre>

</body>

</html>

 

Output

 

pic19.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.