English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
The following table lists the properties of the Document object:
Properties | Description |
---|---|
activeElement | Returns the element currently in focus within the document |
baseURI | Returns the absolute base URI of the document |
body | Set or return the body of the document (element) |
cookie | Returns a semicolon-separated list of cookies for the document |
characterSet | Returns the character set used by the document |
defaultView | Returns the window object associated with the document; if no available window object is found, returns null |
designMode | Get or set the ability to edit the entire document |
doctype | Returns the document type declaration of the current document |
documentElement | Returns the Document element that is a direct child of the document (<html>element) |
documentURI | Sets or returns the document location as a string |
domain | Returns the domain name of the server that loaded the document |
embeds | Returns all<embed>List of elements |
forms | Returns all<form>List of elements |
fullscreenElement | Returns the current element displayed in full-screen mode |
fullscreenEnabled | Returns a boolean value indicating whether the document can be viewed in full-screen mode |
head | Returns the<head>element |
images | Returns all<img>List of elements |
implementation | Returns the DOM implementation associated with the current document |
lastModified | Returns the date and time of the last modification of the document |
links | Returns all elements with the href attribute in the document<a>and<area>Collection of elements |
readyState | Returns the loading status of the document |
referrer | Returns the URL of the document that loaded the current document |
scripts | Returns the<script>List of elements |
title | Sets or returns the document title |
URL | Returns the complete URL of the HTML document as a string |
The following table lists the methods of the Document object:
Method | Description |
---|---|
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 |