JS: document.write

By Xah Lee. Date: . Last updated: .

document.write

document.write insert string into the HTML page, before browser finishes reading the rest of HTML page.

document.write("<p>how are you?</p>");

This is a simple example of inserting text into a document. But this is not a good way.

document.write() is from 1996, when DOM didn't exist yet. It is a blocking construct. When browser encounters it, it stops everything and run the code. document.write() is not used in modern web programing since about 2010.

For a much better way, see: JS: Create and Insert HTML Element .