You are here: Reference > JavaScript > client-side > HTML DOM > methods > clear (document)

clear method (document)

Browser support:
Clears the entire contents of the currently opened document.
The clear method is deprecated and has no effect in the newer versions of commonly used browsers.
Note: the support for the clear method has been removed in Internet Explorer 9.
To clear a document, use the open method without parameters after the document has been loaded. The open method opens the output stream for writing. When the document stream is opened, the write and writeln methods can be used to write some content into the document. If the document was opened by the open method, the close method must be used to close the output stream.
Note: while the document is loading, the document stream is opened for writing. In that case, there is no need to open and close the output stream.
After the document has been loaded, the open method clears the current document (if at most two parameters are specified).


object.clear ( );
You can find the related objects in the Supported by objects section below.

Return value:

This method has no return value.

Example HTML code 1:

This example shows how to clear the document.
    <script type="text/javascript">
        function ClearDoc () {
            document.close ();
    <button onclick="ClearDoc ();">Clear the contents of the document!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content