document.clear() is a deprecated legacy method that does nothing in modern browsers. It does not throw, does not remove nodes, and returns undefined (MDN).
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call document.clear. Start with this line.
JavaScript
document.clear()
Call
What it does
document.clear()
Primary signature.
document.clear(...)
Call with the arguments your case needs.
Built into the browser. Call clear(...) on document — no import required.
Library declarations
JavaScript
document.clear()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Always undefined
JavaScript Examples
Example 1 — clear() Does Not Remove Nodes
Count children before and after — the counts match (MDN no-op).
MDN: Document.clear() does nothing, but does not raise any error. It is a deprecated legacy method kept for compatibility. It does not remove nodes from the page in modern browsers.
Yes. MDN marks Document.clear() as Deprecated. Avoid it in new code. Use modern DOM APIs such as Element.replaceChildren() to empty content.
undefined (MDN). It takes no parameters.
To empty an element: element.replaceChildren() (preferred) or element.innerHTML = "". To rewrite a whole document stream, use document.open(), document.write(), and document.close() carefully.
Browsers keep this legacy no-op so very old scripts that call document.clear() do not throw. The HTML specification defines it as a compatibility stub.
Not in modern browsers — it has no visible effect (MDN). Use replaceChildren() or similar APIs when you need to remove content.