HTML CSS Bootstrap Javascript Icons Python
JavaScript Reference
Overview
JS Reference
JS Array Object JS Boolean Object JS Date Object JS Style Declaration Object JS Error Object JS Global Object JS Math Object JS Number Object JS String Object JS RegExp Object JS Statements
DOM Reference
DOM Attribute DOM Console DOM Document DOM Element DOM Events DOM Event Objects DOM History DOM HTMLCollection DOM Location DOM Navigator DOM Screen DOM Style DOM Window WEB Storage

HTML DOM Document Object

The Document Object

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

The document object is the root node of the HTML document and represents your web page.

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

It provides functionality globally to the document, like how to obtain the page's URL and create new elements in the document.

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

Run code

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


Document Object Properties

The following table lists the properties of the Document object:

Property Description
activeElement Returns the currently focused element in the document
baseURI Returns the absolute base URI of a document
body Sets or returns the document's body (the <body> element)
cookie Returns a semicolon-separated list of the cookies for that document
characterSet Returns the character set being used by the document
defaultView Returns the window object associated with a document, or null if none is available
designMode Gets or sets the ability to edit the whole document
doctype Returns the Document Type Declaration of the current document
documentElement Returns the Document Element that is a direct child of the document (the <html> element)
documentURI Sets or returns the location of the document as a string
domain Returns the domain name of the server that loaded the document
embeds Returns a list of all <embed> elements the document
forms Returns a list of all <form> elements in the document
fullscreenElement Returns the current element that is displayed in fullscreen mode
fullscreenEnabled Returns a Boolean value indicating whether the document can be viewed in fullscreen mode
head Returns the <head> element of the document
images Returns a list of all <img> elements in the document
implementation Returns the DOM implementation associated with the current document
lastModified Returns the date and time the document was last modified
links Returns a collection of all <a> and <area> elements in the document that have a href attribute
readyState Returns loading status of the document
referrer Returns the URL of the document that loaded the current document
scripts Returns a list of <script> elements in the document
title Sets or returns the title of the document
URL Returns the full URL of the HTML document as a string

Document Object Methods

The following table lists the methods of the Document object:

Method Description
addEventListener() Attaches an event handler to the document
adoptNode() Adopt node from an external document
close() Closes a document stream previously opened with document.open()
createAttribute() Creates an attribute node
createComment() Creates a new Comment node with the specified text
createDocumentFragment() Creates a new document fragment node
createElement() Creates a new element node with the given tag name
createTextNode() Creates a Text node
execCommand() Invokes the specified clipboard operation on the element currently having focus.
exitFullscreen() Cancels an element in fullscreen mode
getElementById() Returns the element that has the ID attribute with the specified value
getElementsByClassName() Returns a list of elements with the given class name
getElementsByName() Returns a list of elements with a given name
getElementsByTagName() Returns a list of elements with the given tag name
hasFocus() Returns true if the focus is currently located anywhere inside the specified document
importNode() Returns a clone of a node from an external document
normalize() Removes empty Text nodes, and joins adjacent nodes
normalizeDocument() Removes empty Text nodes, and joins adjacent nodes
open() Opens a document stream for writing
querySelector() Returns the first element that matches a specified CSS selector(s) in the document
querySelectorAll() Returns a list of all elements that matches a specified CSS selector(s) in the document
removeEventListener() Removes an event handler from the document that has been attached with the addEventListener() method
write() Writes HTML expressions or JavaScript code to a document
writeln() Same as write(), but adds a newline character after each statement