Dom Obj Document
* * *
## HTML DOM Nodes
In HTML DOM (Document Object Model), every element is a **node**:
* The document is a document node.
* All HTML elements are element nodes.
* All HTML attributes are attribute nodes.
* Text inserted into HTML elements are text nodes.
* Comments are comment nodes.
* * *
## Document Object
When a browser loads an HTML document, it becomes a **Document Object**.
The Document Object is the root node of the HTML document.
The Document Object allows us to access all elements in the HTML page from scripts.
**Tip:** The Document Object is part of the Window object and can be accessed through the window.document property.
* * *
## Browser Support
]( | Adds a handler to the document |
| [document.adoptNode(node)]( | Returns an adapted node from another document to the current document. |
| [document.anchors]( | Returns a reference to all Anchor objects in the document. |
| document.applets | Returns a reference to all Applet objects in the document. **Note:** The element is not supported in HTML5. |
| [document.baseURI]( | Returns the absolute base URI of the document |
| [document.body]( | Returns the body element of the document |
| [document.close()]( | Closes the output stream opened with the document.open() method and displays the selected data. |
| [document.cookie]( | Sets or returns all cookies associated with the current document. |
| [document.createAttribute()]( | Creates an attribute node |
| [document.createComment()]( | The createComment() method creates a comment node. |
| [document.createDocumentFragment()]( | Creates an empty DocumentFragment object and returns this object. |
| [document.createElement()]( | Creates an element node. |
| [document.createTextNode()]( | Creates a text node. |
| [document.doctype]( | Returns the document type declaration (DTD) associated with the document. |
| [document.documentElement]( | Returns the root node of the document |
| [document.documentMode]( | Returns the mode used by the browser to render the document |
| [document.documentURI]( | Sets or returns the location of the document |
| [document.domain]( | Returns the domain name of the current document. |
| document.domConfig | **Deprecated.** Returns the configuration used when normalizeDocument() is called. |
| [document.embeds]( | Returns a collection of all embedded content (embed) in the document |
| [document.forms]( | Returns a reference to all Form objects in the document. |
| [document.getElementsByClassName()]( | Returns a collection of all elements with the specified class name in the document, as a NodeList object. |
| [document.getElementsById()]( | Returns a reference to the first object with the specified id. |
| [document.getElementsByName()]( | Returns a collection of objects with the specified name. |
| [document.getElementsByTagName()]( | Returns a collection of objects with the specified tag name. |
| [document.images]( | Returns a reference to all Image objects in the document. |
| [document.implementation]( | Returns the DOMImplementation object that handles the document. |
| [document.importNode()]( | Copies a node from another document to this document for use. |
| [document.inputEncoding]( | Returns the encoding used for the document (at the time of parsing). |
| [document.lastModified]( | Returns the date and time when the document was last modified. |
| [document.links]( | Returns a reference to all Area and Link objects in the document. |
| [document.normalize()]( | Removes empty text nodes and merges adjacent nodes |
| [document.normalizeDocument()]( | Removes empty text nodes and merges adjacent nodes |
| [document.open()]( | Opens a stream to collect output from any document.write() or document.writeln() methods. |
| [document.querySelector()]( | Returns the first element in the document that matches the specified CSS selector |
| [document.querySelectorAll()]( | document.querySelectorAll() is a new method introduced in HTML5, returns a list of all element nodes in the document that match the specified CSS selector |
| [document.readyState]( | Returns the document status (loading...) |
| [document.referrer]( | Returns the URL of the document that loaded the current document. |
| [document.removeEventListener()]( | Removes an event handler from the document (added by the addEventListener() method) |
| [document.renameNode()]( | Renames an element or attribute node. |
| [document.scripts]( | Returns a collection of all scripts in the page. |
| [document.strictErrorChecking]( | Sets or returns whether to enforce error checking. |
| [document.title]( | Returns the title of the current document. |
| [document.URL]( | Returns the complete URL of the document |
| [document.write()]( | Writes HTML expressions or JavaScript code to the document. |
| [document.writeln()]( | Similar to write() method, but adds a newline character at the end of each expression. |
YouTip