document Object

Represents the HTML document in a specific window.

Members Table

The following table lists the members exposed by the document object.

Attribute Property Description
activeElement Gets the object that has the focus when the parent document has focus.
alinkColor Sets or gets the color of all active links in the document.
bgColor Deprecated. Sets or retrieves a value that indicates the background color behind the object.
characterSet New for Windows Internet Explorer 9  Gets the name of the character set that is used to encode the document.
CHARSET charset Gets or sets the character set used to encode the object.
compatible Retrieves the collection of user agents and versions declared in the X-UA-Compatible
compatMode Gets a value that indicates whether standards-compliant mode is switched on for the object.
constructor Returns a reference to the constructor of an object.
cookie Sets or gets the string value of a cookie.
defaultCharset Gets the default character set from the current regional language settings.
defaultView New for Internet Explorer 9  Gets a reference to the window object for the document.
designMode Sets or gets a value that indicates whether the document can be edited.
dir Sets or retrieves a value that indicates the reading order of the object.
doctype Gets an object that represents the document type declaration that is associated with the current document.
documentElement Gets a reference to the root node of the document.
documentMode Retrieves the document compatibility mode of the document.
domain Sets or gets the security domain of the document.
expando Gets or sets a value indicating whether arbitrary variables can be created within the object.
fgColor Sets or gets the foreground (text) color of the document.
fileCreatedDate Retrieves the date the file was created.
fileModifiedDate Retrieves the date the file was last modified.
fileSize Retrieves the file size.
head New for Internet Explorer 9  Gets the head element of the document.
implementation Gets the implementation object of the current document.
inputEncoding New for Internet Explorer 9  Gets the character encoding that is used for the text that is loaded into the document object.
lastModified Gets the date that the document was last modified, if the document supplies one.
linkColor Sets or gets the color of the document links.
localName New for Internet Explorer 9  Retrieves the local name of the fully qualified XML declaration for a node.
namespaceURI New for Internet Explorer 9  Retrieves the namespace Uniform Resource Identifier (URI) of the fully qualified XML declaration for a node.
parentWindow Gets a reference to the container object of the window.
prefix New for Internet Explorer 9  Retrieves the local name of the fully qualified XML declaration for a node.
protocol Sets or retrieves the protocol portion of a URL.
readyState Retrieves a value that indicates the current state of the object.
referrer Gets the URL of the location that referred the user to the current document.
rootElement New for Internet Explorer 9  Gets the root svg element in the document hierarchy.
textContent New for Internet Explorer 9  Sets or retrieves the text content of an object and any child objects.
uniqueID Retrieves an autogenerated, unique identifier for the object.
URL Sets or gets the URL for the current document.
URLUnencoded Gets the URL for the document, stripped of any character encoding.
vlinkColor Sets or gets the color of the links that the user has visited.
xmlEncoding New for Internet Explorer 9  Gets a value that represents the character encoding that is specified in the declaration of an XML document.
xmlStandalone New for Internet Explorer 9  Gets or sets the value of the standalone attribute in the declaration of an XML document.
xmlVersion New for Internet Explorer 9  Gets or sets the version attribute that is specified in the declaration of an XML document.
XSLDocument Retrieves a reference to the top-level node of the Extensible Stylesheet Language (XSL) document.
Collection Description
all Returns a reference to the collection of elements contained by the object.
anchors Retrieves a collection of all a objects that have a name and/or id property. Objects in this collection are in HTML source order.
applets Retrieves a collection of all applet objects in the document.
childNodes Retrieves a collection of HTML Elements and TextNode objects that are direct descendants of the specified object.
embeds Retrieves a collection of all embed objects in the document.
forms Retrieves a collection, in source order, of all form objects in the document.
frames Retrieves a collection of all window objects defined by the given document or defined by the document associated with the given window.
images Retrieves a collection, in source order, of img objects in the document.
links Retrieves a collection of all a objects that specify the href property and all area objects in the document.
namespaces Retrieves a collection of namespace objects.
scripts Retrieves a collection of all script objects in the document.
styleSheets Retrieves a collection of styleSheet objects representing the style sheets that correspond to each instance of a link or style object in the document.
Event Event Property Description
abort New for Internet Explorer 9  onabort Fires when the user aborts the download.
onactivate Fires when the object is set as the active element.
onbeforeactivate Fires immediately before the object is set as the active element.
onbeforedeactivate Fires immediately before the activeElement is changed from the current object to another object in the parent document.
onbeforeeditfocus Fires before an object contained in an editable element enters a UI-activated state or when an editable container object is control selected.
blur New for Internet Explorer 9  onblur Fires when the object loses the input focus.
canplay New for Internet Explorer 9  oncanplay Occurs when playback is possible, but would require further buffering.
canplaythrough New for Internet Explorer 9  oncanplaythrough Occurs when playback to end is possible without requiring a stop for further buffering.
oncellchange Fires when data changes in the data provider.
change New for Internet Explorer 9  onchange Fires when the contents of the object or selection have changed.
click onclick Fires when the user clicks the left mouse button on the object.
contextmenu oncontextmenu Fires when the user clicks the right mouse button in the client area, opening the context menu.
oncontrolselect Fires when the user is about to make a control selection of the object.
ondataavailable Fires periodically as data arrives from data source objects that asynchronously transmit their data.
ondatasetchanged Fires when the data set exposed by a data source object changes.
ondatasetcomplete Fires to indicate that all data is available from the data source object.
dblclick ondblclick Fires when the user double-clicks the object.
ondeactivate Fires when the activeElement is changed from the current object to another object in the parent document.
drag New for Internet Explorer 9  ondrag Fires on the source object continuously during a drag operation.
dragend New for Internet Explorer 9  ondragend Fires on the source object when the user releases the mouse at the close of a drag operation.
dragenter New for Internet Explorer 9  ondragenter Fires on the target element when the user drags the object to a valid drop target.
dragleave New for Internet Explorer 9  ondragleave Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation.
dragover New for Internet Explorer 9  ondragover Fires on the target element continuously while the user drags the object over a valid drop target.
dragstart ondragstart Fires on the source object when the user starts to drag a text selection or selected object.
drop New for Internet Explorer 9  ondrop Fires on the target object when the mouse button is released during a drag-and-drop operation.
durationchange New for Internet Explorer 9  ondurationchange Occurs when the duration attribute is updated.
emptied New for Internet Explorer 9  onemptied Occurs when the media element is reset to its initial state.
ended New for Internet Explorer 9  onended Occurs when the end of playback is reached.
error New for Internet Explorer 9  onerror Fires when an error occurs during object loading.
onerrorupdate Fires on a databound object when an error occurs while updating the associated data in the data source object.
focus New for Internet Explorer 9  onfocus Fires when the object receives focus.
focusin onfocusin Fires for an element just prior to setting focus on that element.
focusout onfocusout Fires for the current element with focus immediately after moving focus to another element.
onhelp Fires when the user presses the F1 key while the client is the active window.
input New for Internet Explorer 9  oninput Occurs when the text content of an element is changed through the user interface.
keydown onkeydown Fires when the user presses a key.
keypress onkeypress Fires when the user presses an alphanumeric key.
keyup onkeyup Fires when the user releases a key.
load New for Internet Explorer 9  onload Fires immediately after the client loads the object.
loadeddata New for Internet Explorer 9  onloadeddata Occurs when media data is loaded at the current playback position.
loadedmetadata New for Internet Explorer 9  onloadedmetadata Occurs when the duration and dimensions of the media have been determined.
loadstart New for Internet Explorer 9  onloadstart Occurs when Internet Explorer begins looking for media data.
mousedown onmousedown Fires when the user clicks the object with either mouse button.
mousemove onmousemove Fires when the user moves the mouse over the object.
mouseout onmouseout Fires when the user moves the mouse pointer outside the boundaries of the object.
mouseover onmouseover Fires when the user moves the mouse pointer into the object.
mouseup onmouseup Fires when the user releases a mouse button while the mouse is over the object.
mousewheel onmousewheel Fires when the wheel button is rotated.
mssitemodejumplistitemremoved New for Internet Explorer 9  onmssitemodejumplistitemremoved Occurs when msSiteModeShowJumpList is called, and an item has been removed from a Jump List by the user.
msthumbnailclick New for Internet Explorer 9  onmsthumbnailclick Occurs when a user clicks a button in a Thumbnail Toolbar.
pause New for Internet Explorer 9  onpause Occurs when playback is paused.
play New for Internet Explorer 9  onplay Occurs when the play method is requested.
playing New for Internet Explorer 9  onplaying Occurs when the audio or video has started playing.
progress New for Internet Explorer 9  onprogress Occurs to indicate progress while downloading media data.
onpropertychange Fires when a property changes on the object.
ratechange New for Internet Explorer 9  onratechange Occurs when the playback rate is increased or decreased.
readystatechange onreadystatechange Fires when the state of the object has changed.
onreset New for Internet Explorer 9  Fires when the user resets a form.
onrowenter Fires to indicate that the current row has changed in the data source and new data values are available on the object.
onrowexit Fires just before the data source control changes the current row in the object.
onrowsdelete Fires when rows are about to be deleted from the recordset.
onrowsinserted Fires just after new rows are inserted in the current recordset.
scroll New for Internet Explorer 9  onscroll Fires when the user repositions the scroll box in the scroll bar on the object.
seeked New for Internet Explorer 9  onseeked Occurs when the seek operation ends.
seeking New for Internet Explorer 9  onseeking Occurs when the current playback position is moved.
select New for Internet Explorer 9  onselect Fires when the current selection changes.
onselectionchange Fires when the selection state of a document changes.
stalled New for Internet Explorer 9  onstalled Occurs when the download has stopped.
onstop Fires when the user clicks the Stop button or leaves the document.
storage onstorage Fires when a Web Storage area is updated.
onstoragecommit Fires when a local Web Storage area is written to disk.
suspend New for Internet Explorer 9  onsuspend Occurs if the load operation has been intentionally halted.
timeupdate New for Internet Explorer 9  ontimeupdate Occurs to indicate the current playback position.
volumechange New for Internet Explorer 9  onvolumechange Occurs when the volume is changed, or playback is muted or unmuted.
waiting New for Internet Explorer 9  onwaiting Occurs when playback stops because the next frame of a video resource is not available.
Method Description
addEventListener New for Internet Explorer 9  Registers an event handler for the specified event type.
adoptNode New for Internet Explorer 9  Tries to move a node from one document to the document that the document object displays.
attachEvent Binds the specified function to an event, so that the function gets called whenever the event fires on the object.
clear Not supported.
close Closes an output stream and forces the sent data to display.
compareDocumentPosition New for Internet Explorer 9  Compares the position of two nodes in a document.
createAttribute Creates an attribute object with a specified name.
createAttributeNS New for Internet Explorer 9  Creates a reference to an attribute object that is associated with an XML namespace.
createCDATASection New for Internet Explorer 9  Creates a CDATA section that contains the specified text.
createComment Creates a comment object with the specified data.
createDocumentFragment Creates a new document.
createElement Creates an instance of the element for the specified tag.
createElementNS New for Internet Explorer 9  Creates an element from the specified namespace.
createEvent New for Internet Explorer 9  Creates a Document Object Model (DOM) event of the specified type.
createEventObject Generates an event object to pass event context information when you use the fireEvent method.
createNodeIterator New for Internet Explorer 9  Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
createProcessingInstruction New for Internet Explorer 9  Creates a processing instruction for an XML parser.
createRange New for Internet Explorer 9  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 New for Internet Explorer 9  Creates a TreeWalker object that you can use to traverse filtered lists of nodes or elements in a document.
detachEvent Unbinds the specified function from the event, so that the function stops receiving notifications when the event fires.
dispatchEvent New for Internet Explorer 9  Sends an event to the current element.
elementFromPoint Returns the element for the specified x coordinate and the specified y coordinate.
execCommand Executes a command on the current document, current selection, or the given range.
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 New for Internet Explorer 9  Gets a collection of nodes that match an element name from the specified namespace.
getSelection New for Internet Explorer 9  Returns an object that represents the current selection of the document.
hasFocus Gets a value indicating whether the object currently has focus.
importNode New for Internet Explorer 9  Imports a node from another document into the the document that the document object displays.
isDefaultNamespace New for Internet Explorer 9  Indicates whether or not a namespace is the default namespace for a document.
isEqualNode New for Internet Explorer 9  Determines if two nodes are equal.
isSameNode New for Internet Explorer 9  Determines if two node references refer to the same node.
isSupported New for Internet Explorer 9  Returns a value indicating whether or not the object supports a specific DOM standard.
lookupNamespaceURI New for Internet Explorer 9  Gets the URI of the namespace associated with a namespace prefix, if any.
lookupPrefix New for Internet Explorer 9  Gets the namespace prefix associated with a URI, if any.
normalize New for Internet Explorer 9  Merges adjacent DOM objects to produce a normalized document object model.
open Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method.
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 Recalculates all dynamic properties in the current document.
releaseCapture Removes mouse capture from the object in the current document.
removeEventListener New for Internet Explorer 9  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.
Element Object Description
BODY body Specifies the beginning and end of the document body.
HTMLSelection New for Internet Explorer 9  Represents the active selection, which is typically a highlighted block of text or other elements in the document. The active selection can be used to complete an action issued by a user or a script.
implementation Contains information about the modules supported by the object.
location Contains information about the current URL.
selection Represents the active selection, which is a highlighted block of text or other elements in the document that a user or a script can carry out some action on.
TITLE title Contains the title of the document.
Object Description
HTMLCollection Constructor Defines the properties and methods inherited by objects in the HTMLCollection Constructor prototype chain.
HTMLDocument Constructor Defines the properties and methods inherited by objects in the HTMLDocument Constructor prototype chain.

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.

The document object is available at all times in the primary document, but it does not exist for the HTML Component (HTC) files used in lightweight DHTML behaviors. This is because lightweight behaviors can be defined only if they do not use a document object in the HTC file. As a result, lightweight behaviors run faster and more efficiently than normal behaviors. Lightweight DHTML behaviors can, however, access the document object of the primary document in the same way as normal DHTML behaviors.

It is possible for the script in a behavior to reference the document object in the HTC file or the primary document. When coding script in an HTC file, use element. document to refer to the document object in the primary document.

Examples

This example uses the document object to check for a document title and displays the title (if not null) in a message box.

if (document.title!="")
    alert("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 the status window.

<HTML>
<head><title>Report mouse moves</title>
<script>
function reportMove()
{
    window.status = "X=" + window.event.x + " Y=" + window.event.y;
}
</script>
</head>
<body onmousemove="reportMove()">  
<h1>Welcome!</h1>
</body>
</html>

Standards Information

This object is defined in DOM Level 1.

Applies To

CUSTOM, window