HTML DOM
HTML DOM close() Method
The close() method closes an output stream that was opened with document.open() and forces any written data to be displayed on the page.
Definition and Usage
document.close() closes the document stream that document.open() opened and document.write() wrote to. After a stream is closed, the browser finishes rendering the written content and stops treating further write() calls as part of that stream.
Syntax
document.close()It takes no parameters and returns undefined.
Example
// Open a fresh stream, write to it, then close it
document.open();
document.write("<h1>Hello, DOM!</h1>");
document.write("<p>This content was streamed in.</p>");
document.close();open() clears the current document and starts a new stream. Each write() appends markup, and close() finalizes the stream so the browser renders the completed page and shows the loading indicator as finished.
document.open(), write(), and close() replace the entire page when called after loading. They are legacy APIs - prefer innerHTML or createElement for modern DOM updates.
