English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM write() method

HTML DOM Document Object

write()method writes a text string to the document stream.

Note:when document.write() writes to the document stream, it is called on the loaded documentdocument.write()is automatically calleddocument.open()This will clear the document (see the 'More Examples' below).

Syntax:

document.write(markup)
document.write("<h2>Hello world</2>
Test and see‹/›

Browser Compatibility

All browsers fully support the write() method:

Method
write()IsIsIsIsIs

Parameter Value

ParameterDescription
markupA string containing the text to be written to the document

Technical Details

Return Value:None
DOM Version:DOM 2Level

More Examples

If the document.write() method is used after the page is loaded, it will overwrite all existing content:

document.write("<p>Unique content.</p>
Test and see‹/›

You can also pass comma-separated parameters:

document.write("First Argument", " Second Argument ", new Date());
Test and see‹/›

Related References

DOM Document open()Methods

DOM Document writeln()Methods

DOM Document close()Methods

HTML DOM Document Object