HTML DOM
HTML DOM Complete Reference
This is a quick reference of the most commonly used properties, methods, and collections of the document object in the HTML DOM. Use it as a cheat sheet when writing JavaScript that reads or updates the page.
About This Reference
The document object is the entry point to the DOM. Its members fall into three groups: properties (values you read or set), methods (actions you call), and collections (live lists of specific elements). The table below summarizes the members you will use most often.
Members ending with () are methods you call, like document.getElementById("x"). Members without () are properties or collections you access directly, like document.title or document.forms.
Document Properties, Methods, and Collections
| Name | Description |
|---|---|
| activeElement | Returns the element that currently has focus. |
| anchors | Collection of all <a> elements that have a name attribute. |
| baseURI | Returns the absolute base URI of the document. |
| body | Sets or returns the <body> element of the document. |
| characterSet | Returns the character encoding of the document (e.g. UTF-8). |
| cookie | Sets or returns all cookies associated with the document. |
| createAttribute() | Creates a new attribute node. |
| createComment() | Creates a comment node with the given text. |
| createDocumentFragment() | Creates an empty, lightweight DocumentFragment. |
| createElement() | Creates a new element node with the given tag name. |
| createTextNode() | Creates a new text node with the given text. |
| close() | Closes an output stream opened with document.open(). |
| defaultView | Returns the window object associated with the document. |
| designMode | Sets or returns whether the document is editable. |
| doctype | Returns the Document Type Declaration of the document. |
| documentElement | Returns the root <html> element of the document. |
| documentURI | Sets or returns the location (URI) of the document. |
| domain | Returns the domain name of the server that loaded the document. |
| embeds | Collection of all <embed> elements in the document. |
| forms | Collection of all <form> elements in the document. |
| getElementById() | Returns the element with the specified id. |
| getElementsByClassName() | Returns a collection of elements with the given class name. |
| getElementsByName() | Returns a collection of elements with the given name attribute. |
| getElementsByTagName() | Returns a collection of elements with the given tag name. |
| head | Returns the <head> element of the document. |
| images | Collection of all <img> elements in the document. |
| implementation | Returns the DOMImplementation object for the document. |
| importNode() | Imports a node from another document into this one. |
| lastModified | Returns the date and time the document was last modified. |
| links | Collection of all <a> and <area> elements that have an href. |
| open() | Opens an output stream to collect document.write() output. |
| querySelector() | Returns the first element matching a CSS selector. |
| querySelectorAll() | Returns all elements matching a CSS selector. |
| readyState | Returns the loading status of the document. |
| referrer | Returns the URL of the page that linked to this document. |
| scripts | Collection of all <script> elements in the document. |
| title | Sets or returns the title of the document. |
| URL | Returns the full URL of the document. |
| write() | Writes HTML or JavaScript output to the document. |
| writeln() | Writes to the document, followed by a newline character. |
For a focused explanation of any single member, see its dedicated page in this HTML DOM section.
Prefer querySelector and querySelectorAll for flexible CSS-selector-based lookups, and getElementById for fast, direct access by id.
