JavaScript: document.write

By Xah Lee. Date: . Last updated: .

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: JavaScript: Create and Insert HTML Element .

JavaScript in Depth

DOM Scripting


DOM Methods

Basic Examples

HTML Input

Web Scripting Examples

Web Scripting Misc