Represents the HTML document in a specific window.
![]() |
DOM Information
Inheritance Hierarchy
Members
The document object has these types of members:
Events
The document object has these events.
| Event | Description |
|---|---|
| abort |
Fires when the user aborts the download. |
| activate |
Fires when the object is set as the active element. |
| beforeactivate |
Fires immediately before the object is set as the active element. |
| blur |
Fires when the object loses the input focus. |
| canplay |
Occurs when playback is possible, but would require further buffering. |
| canplaythrough |
Occurs when playback to end is possible without requiring a stop for further buffering. |
| change |
Fires when the contents of the object or selection have changed. |
| click |
Fires when the user clicks the left mouse button on the object. |
| contextmenu |
Fires when the user clicks the right mouse button in the client area, opening the context menu. |
| dblclick |
Fires when the user double-clicks the object. |
| deactivate |
Fires when the activeElement is changed from the current object to another object in the parent document. |
| DOMContentLoaded |
Fires when a webpage has been parsed, but before all resources have been fully downloaded. |
| drag |
Fires on the source object continuously during a drag operation. |
| dragend |
Fires on the source object when the user releases the mouse at the close of a drag operation. |
| dragenter |
Fires on the target element when the user drags the object to a valid drop target. |
| dragleave |
Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation. |
| dragover |
Fires on the target element continuously while the user drags the object over a valid drop target. |
| dragstart |
Fires on the source object when the user starts to drag a text selection or selected object. |
| drop |
Fires on the target object when the mouse button is released during a drag-and-drop operation. |
| durationchange |
Occurs when the duration attribute is updated. |
| emptied |
Occurs when the media element is reset to its initial state. |
| ended |
Occurs when the end of playback is reached. |
| error |
Fires when an error occurs during object loading. |
| focus |
Fires when the object receives focus. |
| focusin |
Fires for an element just prior to setting focus on that element. |
| focusout |
Fires for the current element with focus immediately after moving focus to another element. |
| input |
Occurs when the text content of an element is changed through the user interface. |
| keydown |
Fires when the user presses a key. |
| keypress |
Fires when the user presses an alphanumeric key. |
| load |
Fires immediately after the client loads the object. |
| loadeddata |
Occurs when media data is loaded at the current playback position. |
| loadedmetadata |
Occurs when the duration and dimensions of the media have been determined. |
| loadstart |
Occurs when Internet Explorer begins looking for media data. |
| mousedown |
Fires when the user clicks the object with either mouse button. |
| mousemove |
Fires when the user moves the mouse over the object. |
| mouseout |
Fires when the user moves the mouse pointer outside the boundaries of the object. |
| mouseover |
Fires when the user moves the mouse pointer into the object. |
| mouseup |
Fires when the user releases a mouse button while the mouse is over the object. |
| MSPointerCancel |
Fires when the system cancels a pointer event. |
| onbeforedeactivate |
Fires immediately before the activeElement is changed from the current object to another object in the parent document. |
| onkeyup |
Fires when the user releases a key. |
| onselect |
Fires when the current selection changes. |
| pause |
Occurs when playback is paused. |
| play |
Occurs when the play method is requested. |
| playing |
Occurs when the audio or video has started playing. |
| progress |
Occurs to indicate progress while downloading media data. |
| ratechange |
Occurs when the playback rate is increased or decreased. |
| readystatechange |
Fires when the state of the object has changed. |
| reset |
Fires when the user resets a form. |
| scroll |
Fires when the user repositions the scroll box in the scroll bar on the object. |
| seeked |
Occurs when the seek operation ends. |
| seeking |
Occurs when the current playback position is moved. |
| stalled |
Occurs when the download has stopped. |
| storage |
Fires when a Web Storage area is updated. |
| suspend |
Occurs if the load operation has been intentionally halted. |
| timeupdate |
Occurs to indicate the current playback position. |
| visibilitychange |
Triggered when the visibilityState property changes. |
| volumechange |
Occurs when the volume is changed, or playback is muted or unmuted. |
| waiting |
Occurs when playback stops because the next frame of a video resource is not available. |
Methods
The document object has these methods.
| Method | Description |
|---|---|
| addEventListener |
Registers an event handler for the specified event type. |
| adoptNode |
Tries to move a node from one document to the document that the document object displays. |
| close |
Closes an output stream and forces the sent data to display. |
| compareDocumentPosition |
Compares the position of two nodes in a document. |
| createAttribute | |
| createAttributeNS |
Creates a reference to an attribute object that is associated with an XML namespace. |
| createCDATASection |
Creates a CDATA section that contains the specified text. |
| createComment | |
| createDocumentFragment |
Creates a new document. |
| createElement |
Creates an instance of the element for the specified tag. |
| createElementNS |
Creates an element from the specified namespace. |
| createEvent |
Creates a DOM event of the specified type. |
| createNodeIterator |
Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document. |
| createProcessingInstruction |
Creates a processing instruction for an XML parser. |
| createRange |
Returns an empty range object that has both of its boundary points positioned at the beginning of the document. |
| createStyleSheet |
Creates a style sheet for the document. |
| createTextNode |
Creates a text string from the specified value. |
| createTreeWalker |
Creates a TreeWalker object that you can use to traverse filtered lists of nodes or elements in a document. |
| dispatchEvent |
Sends an event to the current element. |
| elementFromPoint |
Returns the element for the specified x coordinate and the specified y coordinate. |
| execCommandShowHelp |
Displays help information for the given command identifier. |
| focus |
Causes the element to receive the focus and executes the code specified by the onfocus event. |
| getElementById |
Returns a reference to the first object with the specified value of the ID or NAME attribute. |
| getElementsByName |
Gets a collection of objects based on the value of the NAME or ID attribute. |
| getElementsByTagName |
Retrieves a collection of objects based on the specified element name. |
| getElementsByTagNameNS |
Gets a collection of nodes that match an element name from the specified namespace. |
| getSelection |
Returns an object that represents the current selection of the document. |
| hasFocus |
Gets a value indicating whether the object currently has focus. |
| importNode |
Imports a node from another document into the the document that the document object displays. |
| isDefaultNamespace |
Indicates whether or not a namespace is the default namespace for a document. |
| isEqualNode |
Determines if two nodes are equal. |
| isSameNode |
Determines if two node references refer to the same node. |
| isSupported |
Returns a value indicating whether or not the object supports a specific DOM standard. |
| lookupNamespaceURI |
Gets the URI of the namespace associated with a namespace prefix, if any. |
| lookupPrefix |
Gets the namespace prefix associated with a URI, if any. |
| normalize |
Merges adjacent DOM objects to produce a normalized document object model. |
| open |
Opens a document for writing. |
| queryCommandEnabled |
Returns a Boolean value that indicates whether a specified command can be successfully executed using execCommand, given the current state of the document. |
| queryCommandIndeterm |
Returns a Boolean value that indicates whether the specified command is in the indeterminate state. |
| queryCommandState |
Returns a Boolean value that indicates the current state of the command. |
| queryCommandSupported |
Returns a Boolean value that indicates whether the current command is supported on the current range. |
| queryCommandText |
Retrieves the string associated with a command. |
| queryCommandValue |
Returns the current value of the document, range, or current selection for the given command. |
| querySelector |
Retrieves the first DOM element node from descendants of the starting element node that match any selector within the supplied selector string. |
| querySelectorAll |
Retrieves all DOM element nodes from descendants of the starting element node that match any selector within the supplied selector strings. |
| recalc |
This element is obsolete and should no longer be used. Recalculates all dynamic properties in the current document. |
| removeEventListener |
Removes an event handler that the addEventListener method registered. |
| updateSettings |
Allows updating the print settings for the page. |
| write |
Writes one or more HTML expressions to a document in the specified window. |
| writeln |
Writes one or more HTML expressions, followed by a carriage return, to a document in the specified window. |
Properties
The document object has these properties.
| Property | Description |
|---|---|
|
Gets the object that has the focus when the parent document has focus. | |
|
Sets or gets the color of all active links in the document. | |
|
Retrieves a collection of all a objects that have a name and/or id property. Objects in this collection are in HTML source order. | |
|
Gets the name of the character set that is used to encode the document. | |
|
Sets or retrieves the character set used to encode the object. | |
|
Retrieves the collection of user agents and versions declared in the | |
|
Gets a value that indicates whether standards-compliant mode is switched on for the object. | |
|
Returns a reference to the constructor of an object. | |
|
Sets or gets the string value of a cookie. | |
|
Gets the default character set from the current regional language settings. | |
|
Gets a reference to the window object for the document. | |
|
Sets or gets a value that indicates whether the document can be edited. | |
|
Sets or retrieves a value that indicates the reading order of the object. | |
|
Gets an object that represents the document type declaration that is associated with the current document. | |
|
Gets a reference to the root node of the document. | |
|
Retrieves the document compatibility mode of the document. | |
|
Sets or gets the security domain of the document. | |
|
Sets or retrieves a value indicating whether arbitrary variables can be created within the object. | |
|
Sets or gets the foreground (text) color of the document. | |
|
Retrieves the date the file was created. | |
|
Retrieves the date the file was last modified. | |
|
Retrieves the file size. | |
|
Gets the head element of the document. | |
|
Gets the implementation object of the current document. | |
|
Gets the character encoding that is used for the text that is loaded into the document object. | |
|
Gets the date that the document was last modified, if the document supplies one. | |
|
Sets or gets the color of the document links. | |
|
Retrieves the local name of the fully qualified XML declaration for a node. | |
|
Retrieves the namespace URI of the fully qualified XML declaration for a node. | |
|
Gets a reference to the container object of the window. | |
|
Retrieves the local name of the fully qualified XML declaration for a node. | |
|
Retrieves a value that indicates the current state of the object. | |
|
Gets the URL of the location that referred the user to the current document. | |
|
Gets the root svg element in the document hierarchy. | |
|
Sets or retrieves the text content of an object and any child objects. | |
|
Retrieves an autogenerated, unique identifier for the object. | |
|
Sets or gets the URL for the current document. | |
|
Gets the URL for the document, stripped of any character encoding. | |
|
Returns the visibility state of a webpage. | |
|
Sets or gets the color of the links that the user has visited. | |
|
Gets a value that represents the character encoding that is specified in the declaration of an XML document. | |
|
Gets or sets the value of the standalone attribute in the declaration of an XML document. | |
|
Gets or sets the version attribute that is specified in the declaration of an XML document. | |
|
Retrieves a reference to the top-level node of the XSL document. |
Standards information
- Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
Remarks
Use the document object to examine, modify, or add content to an HTML document and to process events within that document. In a script, the document object can be referenced through the document property of the window object or it can be referenced directly.
The ondocumentready event notifies Dynamic HTML (DHTML) behaviors that the document object is available from the primary document containing the behavior. After ondocumentready has fired, a behavior can begin to manipulate the primary document object.
In Windows CE, the document object is not available through scripting for a window object opened using the open method.
Examples
This example uses the document object to check for a document title and displays the title (if not null) in a debugging console window (see F12 Developer Tools for more information).
if (document.title != "") {
console.log("The title is " + document.title)
}
This example shows an event handler function that displays the current position of the mouse, relative to the upper-left corner of the document, in a console window.
<html>
<head>
<title>Report mouse moves</title>
<script>
function reportMove()
{
console.log("X = " + window.event.x + ", Y = " + window.event.y);
}
</script>
</head>
<body onmousemove="reportMove()">
<h1>Welcome!</h1>
</body>
</html>
Build date: 11/28/2012
