In JavaScript, new Document() creates a new Document object - an in-memory web document you can build with DOM APIs. It does not replace the live page document (window.document).
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Create a Document. Start with this line.
JavaScript
new Document()
Call
What it does
new Document()
Primary signature.
Built into the browser. Call new Document() — no import required.
Library declarations
JavaScript
new Document()
Parameters
Parameter
Description
new
Required. Must use the constructor form
Return Value
Return Value
Description
*
A new Document instance
JavaScript Examples
Example 1 - Basic new Document()
Create a document and check its node type and empty root.
Mutate only doc. Appending a root affects the new document only.
Page unchanged. Title and the live <html> root stay the same.
Compatibility
Browser Support
The Document() constructor is marked Baseline Widely available on MDN (since April 2018). Available in modern browsers; not Internet Explorer.
✓ Baseline · Widely available
Document()
Create in-memory Document objects across modern browsers.
97%Core tag support
ChromeYes
Full support
EdgeYes
Full support
FirefoxYes
Full support
SafariYes
Full support
OperaYes
Full support
HTML element100% supported
Bottom line: Safe for modern web apps. For HTML skeletons, also learn createHTMLDocument().
Frequently Asked Questions
It creates a new in-memory Document object. That document is separate from the live page (window.document) until you explicitly move or import nodes into the page.
No. MDN marks Document() as Baseline Widely available (since April 2018). It is not Deprecated, Experimental, or Non-standard.
No. Call it as new Document() with no arguments (MDN).
new Document() starts empty (documentElement is null until you append a root). document.implementation.createHTMLDocument(title) returns an HTML document that already has html, head, and body.
No. window.document is the browsing context's live document. new Document() only creates another Document object for building or testing trees offline.
Use importNode or adoptNode (nodes are owned by a document). Do not assume appendChild works across documents without importing or adopting first.