English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM Document Object

Document Object

The Document object is the owner of all other objects in your web page.

The Document object is the root node of an HTML document, representing your web page.

If you want to access any element in an HTML page, you always start by accessing the Document object.

It provides global functions for the document, such as how to get the page URL and create new elements in the document.

This example uses the getElementById() method to find an HTML element (with id="para"):

document.getElementById("para");
Test to see‹/›

The Document object is the root node of an HTML document.

Document Object Properties

The following table lists the properties of the Document object:

PropertiesDescription
activeElementReturns the element currently in focus within the document
baseURIReturns the absolute base URI of the document
bodySet or return the body of the document (element)
cookieReturns a semicolon-separated list of cookies for the document
characterSetReturns the character set used by the document
defaultViewReturns the window object associated with the document; if no available window object is found, returns null
designModeGet or set the ability to edit the entire document
doctypeReturns the document type declaration of the current document
documentElementReturns the Document element that is a direct child of the document (<html>element)
documentURISets or returns the document location as a string
domainReturns the domain name of the server that loaded the document
embedsReturns all<embed>List of elements
formsReturns all<form>List of elements
fullscreenElementReturns the current element displayed in full-screen mode
fullscreenEnabledReturns a boolean value indicating whether the document can be viewed in full-screen mode
headReturns the<head>element
imagesReturns all<img>List of elements
implementationReturns the DOM implementation associated with the current document
lastModifiedReturns the date and time of the last modification of the document
linksReturns all elements with the href attribute in the document<a>and<area>Collection of elements
readyStateReturns the loading status of the document
referrerReturns the URL of the document that loaded the current document
scriptsReturns the<script>List of elements
titleSets or returns the document title
URLReturns the complete URL of the HTML document as a string

Document object methods

The following table lists the methods of the Document object:

MethodDescription
addEventListener()Attach an event handler to the document
adoptNode()Adopt a node from an external document
close()Close the document stream previously opened with document.open()
createAttribute()Create an attribute node
createComment()Create a new Comment node with the specified text
createDocumentFragment()Create a new document fragment node
createElement()Create a new element node with the given tag name
createTextNode()Create a text node
execCommand()Invoke the specified clipboard operation on the element currently focused
exitFullscreen()Exit the element in full-screen mode
getElementById()Returns the element with the specified ID attribute value
getElementsByClassName()Returns a list of elements with the given class name
getElementsByName()Returns a list of elements with the given name
getElementsByTagName()Return a list of elements with the given tag name
hasFocus()Return true if the focus is currently located at any position within the specified document
importNode()Return a clone of the node from an external document
normalize()Delete empty Text nodes and connect adjacent nodes
normalizeDocument()Delete empty Text nodes and connect adjacent nodes
open()Open a document stream for writing
querySelector()Return the first element that matches the specified CSS selector in the document
querySelectorAll()Return a list of all elements that match the specified CSS selector in the document
removeEventListener()Remove the event handler from the document that has been attached with addEventListener()
write()Write HTML expressions or JavaScript code to the document
writeln()Similar to write(), but adds a newline character after each statement