You are on page 1of 7

HTML DOM Document Objects

The HTML DOM Document Object

Previous Next


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

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

Browser Support[14-06-2017 15:03:14]
HTML DOM Document Objects


Document Yes Yes Yes Yes Yes

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.activeElement Returns the currently focused element in the


document.addEventListener() Attaches an event handler to the document

document.adoptNode() Adopts a node from another document

document.anchors Returns a collection of all <a> elements in the

document that have a name attribute

document.applets Returns a collection of all <applet> elements in the


document.baseURI Returns the absolute base URI of a document

document.body Sets or returns the document's body (the <body>


document.close() Closes the output stream previously opened with

document.cookie Returns all name/value pairs of cookies in the


document.charset Deprecated. Use document.characterSet instead.

Returns the character encoding for the document

document.characterSet Returns the character encoding for 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[14-06-2017 15:03:14]
HTML DOM Document Objects

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.documentURI Sets or returns the location of the document

document.domain Returns the domain name of the server that loaded

the document

document.domConfig Obsolete. Returns the DOM configuration of the


document.embeds Returns a collection of all <embed> elements the


document.forms Returns a collection of all <form> elements in the


document.getElementById() Returns the element that has the ID attribute with

the specified value

document.getElementsByClassName() Returns a NodeList containing all elements with the

specified class name

document.getElementsByName() Returns a NodeList containing all elements with a

specified name

document.getElementsByTagName() Returns a NodeList containing all elements with the

specified tag name

document.hasFocus() Returns a Boolean value indicating whether the

document has focus

document.head Returns the <head> element of the document

document.images Returns a collection of all <img> elements in the


document.implementation Returns the DOMImplementation object that handles

this document

document.importNode() Imports a node from another document[14-06-2017 15:03:14]
HTML DOM Document Objects

document.inputEncoding Returns the encoding, character set, used for the


document.lastModified Returns the date and time the document was last

document.links Returns a collection of all <a> and <area> elements

in the document that have a href attribute

document.normalize() Removes empty Text nodes, and joins adjacent


document.normalizeDocument() Removes empty Text nodes, and joins adjacent

nodes Opens an HTML output stream to collect output from


document.querySelector() Returns the first element that matches a specified

CSS selector(s) in the document

document.querySelectorAll() Returns a static NodeList containing all elements

that matches a specified CSS selector(s) in the

document.readyState Returns the (loading) status of the document

document.referrer Returns the URL of the document that loaded the

current document

document.removeEventListener() Removes an event handler from the document (that

has been attached with the addEventListener()

document.renameNode() Renames the specified node

document.scripts Returns a collection of <script> elements in the


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 HTML document

document.write() Writes HTML expressions or JavaScript code to a


document.writeln() Same as write(), but adds a newline character after[14-06-2017 15:03:14]
HTML DOM Document Objects

each statement

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

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[14-06-2017 15:03:14]
HTML DOM Document Objects


Convert Weights
Animated Buttons
Side Navigation
Top Navigation
JS Animations
Modal Boxes
Progress Bars
Login Form
HTML Includes
Google Maps
Filter List
Sort List


HTML, CSS, JavaScript, PHP, jQuery, Bootstrap and XML.

Read More[14-06-2017 15:03:14]
HTML DOM Document Objects


Top 10 Tutorials Top 10 References

HTML Tutorial HTML Reference
CSS Tutorial CSS Reference
JavaScript Tutorial JavaScript Reference
W3.CSS Tutorial W3.CSS Reference
Bootstrap Tutorial Browser Statistics
SQL Tutorial PHP Reference
PHP Tutorial HTML Colors
jQuery Tutorial HTML Character Sets
Angular Tutorial jQuery Reference
XML Tutorial AngularJS Reference

Top 10 Examples Web Certificates

HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
W3.CSS Examples jQuery Certificate
HTML DOM Examples PHP Certificate
PHP Examples Bootstrap Certificate
ASP Examples XML Certificate
jQuery Examples
Angular Examples
XML Examples

W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve reading and basic
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness of all content.
While using this site, you agree to have read and accepted our terms of use,
cookie and
privacy policy.
Copyright 1999-2017 by Refsnes Data. All Rights Reserved.
Powered by W3.CSS.[14-06-2017 15:03:14]