javascript document.write() method

document.write() in javascript

This is used to display a given text in a web page.

This is mainly used for testing purpose.

Example 1 - Write string

Try Yourself

Example 2 - Write html content

Try Yourself

When document.write() is executed after the page load it will erase all the contents in the web page and only show the text inside it.

Example

Try Yourself