HTML DOM Document Objects

## JavaScript Reference

Overview

## JavaScript Objects

JS Array JS Boolean JS Date JS Math JS Number JS String JS RegExp JS Global

## Browser Objects

Window Navigator Screen History Location

## HTML DOM Objects

DOM Document DOM Elements DOM Attributes DOM Events

## HTML Objects

DOM Anchor DOM Area DOM Base DOM Body DOM Button DOM Form DOM Frame/IFrame DOM Frameset DOM Image DOM Input Button DOM Input Checkbox DOM Input File DOM Input Hidden DOM Input Password DOM Input Radio DOM Input Reset DOM Input Submit DOM Input Text DOM Link DOM Meta DOM Object DOM Option DOM Select DOM Style DOM Table DOM td / th DOM tr DOM Textarea

# The HTML DOM Document Object

« Previous
Next Reference »

## HTML DOM Nodes

In the HTML DOM (Document Object Model), everything is a node:

- The document itself is a document node
- All HTML elements are element nodes
- All HTML attributes are attribute nodes
- Text inside HTML elements are text nodes
- Comments are comment nodes

## The Document Object

When an HTML document is loaded into a web browser, it becomes a document object.

The document object is the root node of the HTML document and the "owner" of all other nodes:
(element nodes, text nodes, attribute nodes, and comment nodes).

The document object provides properties and methods to access all node objects, from within JavaScript.

Tip: The document is a part of the window object and can be accessed as window.document.

## Browser Support

The Document Object is supported in all major browsers.

## Document Object Properties and Methods

The following properties and methods can be used on HTML documents:

Property / Method | Description
--- | ---
document.adoptNode(node) | Returns an adapded node from another document to this document.
document.anchors | Returns a collection of all the anchors in the document
document.applets | Returns a collection of all the applets in the document
document.baseURI | Returns the absolute base URI of a document
document.body | Returns the body element of the document
document.close() | Closes the output stream previously opened with document.open()
document.cookie | Returns all name/value pairs of cookies in the document
document.createAttribute() | Creates an attribute node
document.createComment() | Creates a Comment node with the specified text
document.createDocumentFragment() | Creates an empty DocumentFragment node
document.createElement() | Creates an Element node
document.createTextNode() | Creates a Text node
document.doctype | Returns the Document Type Declaration associated with the document
document.documentElement | Returns the Document Element of the document (the HTML element)
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 server that loaded the document
document.domConfig | Returns the configuration used when normalizeDocument() is invoked
document.forms | Returns a collection of all the forms in the document
document.getElementById() | Returns the element that has the ID attribute with the specified value
document.getElementsByName() | Accesses all elements with a specified name
document.getElementsByTagName() | Returns a NodeList containing all elements with the specified tagname
document.images | Returns a collection of all the images in the document
document.implementation | Returns the DOMImplementation object that handles this document
document.importNode() | Imports a node from another document
document.inputEncoding | Returns the encoding, character set, used for the document
document.lastModified | Returns the date and time the document was last modified
document.links | Returns a collection of all the links in the document
document.normalize() | Removes empty Text nodes, and joins adjacent nodes
document.normalizeDocument() | Removes empty Text nodes, and joins adjacent nodes
document.open() | Opens an HTML output stream to collect output from document.write()
document.readyState | Returns the (loading) status of the document
document.referrer | Returns the URL of the document that loaded the current document
document.renameNode() | Renames the specified node
document.strictErrorChecking | Sets or returns whether error-checking is enforced or not
document.title | Sets or returns the title of the document
document.URL | Returns the full URL of the document
document.write() | Writes HTML expressions or JavaScript code to a document
document.writeln() | Same as write(), but adds a newline character after each statement

## Warning !!!

In the W3C DOM Core, the Document object inherits all properties and methods from the Node object.

Many of these properties and methods make no sense used on documents.

Avoid using these node object properties and methods on HTML document objects:

Property / Method | Reason for avoiding
--- | ---
document.attributes | Documents don't have attributes
document.hasAttributes() | Documents don't have attributes
document.nextSibling | Documents don't have siblings
document.nodeName | This is always #document
document.nodeType | This is always 9 (DOCUMENT_NODE)
document.nodeValue | Documents don't have an node value
document.ownerDocument | Documents don't have an owner document
document.ownerElement | Documents don't have an owner element
document.parentNode | Documents don't have a parent node
document.previousSibling | Documents don't have siblings
document.textContent | Documents don't have a text content

« Previous
Next Reference »

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE