DOM Document Interface
The Document interface represents the whole web page loaded in the browser. The global document object is your starting point for finding, creating and changing elements.
Description
The Document interface represents a web page loaded in the browser and is the entry point to the DOM tree. The global document object gives you the page's <html>, <head> and <body> elements, methods to find elements (getElementById(), querySelector()) and create them (createElement()), and information such as the title, URL, readyState and cookie.
It inherits from Node and EventTarget, so you can listen for document-level events such as DOMContentLoaded, visibilitychange and keyboard events.
Besides the main page, a Document can represent the content of an iframe (through iframe.contentDocument), a document created with document.implementation.createHTMLDocument(), or an HTML or XML document parsed with DOMParser. Methods such as createElement() create nodes that belong to a particular document, which is why you normally use the global document to create elements for the page.
Inheritance
Document inherits properties and methods from Node.
Properties
| Name | Description |
|---|---|
Document.activeElement | The activeElement property returns the element that currently has keyboard focus. |
Document.body | The body property returns the page's body element. |
Document.cookie | The cookie property reads all cookies for the page as one string, or writes a single cookie when assigned. |
Document.documentElement | The documentElement property returns the root element of the page, the html element. |
Document.head | The head property returns the page's head element, where you can add style sheets, scripts and meta tags with JavaScript. |
Document.readyState | The readyState property tells you how far the page has loaded: loading, interactive or complete. |
Document.title | The title property gets or sets the page title shown in the browser tab. |
Methods
| Name | Description |
|---|---|
Document.createDocumentFragment() | The createDocumentFragment() method creates an empty DocumentFragment, an off-screen container for building groups of elements. |
Document.createElement() | The createElement() method creates a new HTML element, which you can then fill in and add to the page. |
Document.getElementById() | The getElementById() method finds the element with a given id. |
Document.querySelector() | The document.querySelector() method returns the first element in the page that matches a CSS selector, or null. |
Document.querySelectorAll() | The document.querySelectorAll() method returns a list of every element in the page that matches a CSS selector. |
Events
| Name | Description |
|---|---|
Document: DOMContentLoaded event | The DOMContentLoaded event fires when the HTML has been fully parsed and the DOM is ready, without waiting for images and style sheets to load. |
Example
Browser Support
The following information will show you the current browser support for the Document interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





