Document object (Object/HTML)

An object that represents the document currently loaded into the window. This exposes the contents of the HTML document through a variety of collections and properties.

Availability:

DOM level - 1
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Opera - 3.0
Inherits from:Element object
JavaScript syntax:-myDocument = document
-myDocument = document.documentElement
IEmyDocument = myElement.document
IEmyDocument = myElement.offsetParent
-myDocument = myElement.ownerDocument
IEmyDocument = myElement.parentElement
-myDocument = myElement.parentNode
-myDocument = myFrame.document
NmyDocument = myLayer.document
-myDocument = myWindow.document
-myDocument = opener.document
-myDocument = self.document
Argument list:anIndexAn index that selects this document
Object properties:<form_name>, activeElement, alinkColor, background, bgColor, body, characterset, charset, cookie, defaultCharset, designMode, doctype, documentElement, domain, expando, fgColor, fileCreatedDate, fileModifiedDate, fileSize, height, implementation, lastModified, linkColor, location, parentWindow, protocol, readyState, referrer, selection, title, uniqueID, URL, vlinkColor, width
Object methods:attachEvent(), captureEvents(), clear(), close(), contextual(), createAttribute(), createCDATASection(), createComment(), createDocumentFragment(), createElement(), createEntityReference(), createProcessingInstruction(), createStyleSheet(), createTextNode(), detachEvent(), elementFromPoint(), execCommand(), getElementById(), getElementsByName(), getElementsByTagName(), getSelection(), handleEvent(), mergeAttrbutes(), open(), queryCommandEnabled(), queryCommandIndeterm(), queryCommandState(), queryCommandSupported(), queryCommandText(), queryCommandValue(), recalc(), releaseEvents(), routeEvent(), write(), writeln()
Functions:captureEvents(), releaseEvents(), routeEvent()
Event handlers:onAfterUpdate, onBeforeCut, onBeforEditFocus, onBeforePaste, onBeforeUpdate, onClick, onContextMenu, onCut, onDblClick, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onErrorUpdate, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onPaste, onPropertyChange, onReadyStateChange, onRowEnter, onRowExit, onSelectStart, onStop
Collections:all[], anchors[], applets[], classes[], embeds[], forms[], frames[], ids[], images[], layers[], links[], plugins[], scripts[], styleSheets[], tags[]

The document object is the root of a hierarchy that describes the document in terms of objects, properties and methods that can operate on those objects.

The DOM level specification describes a core Document object and distinguishes that from the HTMLDocument that is a sub-class of it. However, the browsers do not make such a fine distinction and so Documents and HTMLDocuments are considered to be one and the same. This works because an HTMLDocument inherits the behavior of a DOM core Document object.

Documents and their child objects can respond to events by means of event handler functions. These are generally associated with one another by means of the HTML tag attributes that correspond to each event.

Although there is a superset of all event types, each object type only responds to a few of them.

The document object is based on the Element object, therefore it inherits all the properties and methods of that class and adds others itself.

The document object is basically derived initially from the <BODY> HTML tag, although it contains some properties that are associated with the <HEAD> HTML tag and others from the <HTML> HTML tag that encloses the entire file. The document type header also affects properties in the document object.

Traversing the document object model in MSIE is quite straightforward. In Netscape prior to version 6.0 it is so difficult as to be virtually impossible. You can access certain parts of the DOM in earlier Netscape browsers by virtue of the forms, applets, embeds and other collections but you cannot access other parts of the DOM at all.

Event handling support via properties containing function objects was added to Anchor objects at version 1.1 of JavaScript and is significantly extended in Netscape 6.0 where it supports DOM level 2 capabilities.

Because you might refer to documents in many ways, possibly by means of object properties or as a property belonging to another window, it is not safe to assume that the document property belonging to the Global object is always the documentobject you are trying to access. Indeed, a document may belong to a window, frame, layer or Iframe and several may be accessible at once. Because of this, the object references in the syntax examples assume the object is being referred to via a variable called myDocument or myObject etc. In the object descriptions, the value myDocument is shown being assigned as a variable from the many alternative sources that you can obtain a document reference.

The DOM level specification deprecates the following properties in favor of their counterparts belonging to the BODY object:

The DOM level 2 specification adds the following methods:

A new suite of functionality relating to the way documents are viewed is introduced at DOM level 2. This is embodied in the following classes:

DOM level 3 expects to add the following properties to the document object:

It is also expected to add the following methods:

Warnings:

See also:BODY object, Element.document, Form.handleEvent(), Frame object, HTML object, JavaScript Style Sheets, Layer.document, Node object, Node.ownerDocument, TextRange.queryCommandEnabled(), TextRange.queryCommandIndeterm(), TextRange.queryCommandState(), TextRange.queryCommandSupported(), TextRange.queryCommandText(), TextRange.queryCommandValue(), Window object, Window.document, Window.frames[], Window.opener

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
<form_name>1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a n/aWarning
activeElement n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
alinkColor1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a0 0 n/a n/aWarning , Deprecated
background n/a n/a n/a n/a n/a n/a n/a0 0 n/a n/aDeprecated
bgColor1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a0 0 n/a n/aWarning , Deprecated
body1.5 1.53.0 3.06.0 6.04.0 4.05.0 5.0 n/a n/a1 1 n/a n/aReadOnly
characterset1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a n/a n/a n/a-
charset n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
cookie1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning
defaultCharset n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
designMode n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/aWarning
doctype1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a1 1 n/a n/aWarning , ReadOnly
documentElement1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/aWarning , ReadOnly
domain1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a1 1 n/a n/aWarning , ReadOnly
expando n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
fgColor1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a0 0 n/a n/aWarning , Deprecated
fileCreatedDate n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
fileModifiedDate n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
fileSize n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
height1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
implementation1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/aWarning , ReadOnly
lastModified1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a n/aReadOnly
linkColor1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a0 0 n/a n/aWarning , Deprecated
location1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning , Deprecated
parentWindow n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
protocol n/a1.0 1.0 n/a3.02 3.02 n/a n/a n/a n/a n/a n/aReadOnly
readyState n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly
referrer1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning , ReadOnly
selection n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning , ReadOnly
title1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning
uniqueID n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
URL1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a1 1 n/a n/aReadOnly
vlinkColor1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a0 0 n/a n/aWarning , Deprecated
width1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
attachEvent() n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
captureEvents()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , Deprecated
clear()1.0 1.01.0 1.02.0 2.03.02 3.025.0 5.0 n/a n/a n/a n/a n/aWarning , Deprecated
close()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/a-
contextual()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning , Deprecated
createAttribute()1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a1 1 n/a n/a-
createCDATASection()1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a1 1 n/a n/a-
createComment()1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a1 1 n/a n/a-
createDocumentFragment()1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a1 1 n/a n/a-
createElement()1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a1 1 n/a n/a-
createEntityReference()1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a1 1 n/a n/a-
createProcessingInstruction()1.5 1.5 n/a6.0 6.0 n/a n/a n/a n/a1 1 n/a n/a-
createStyleSheet() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
createTextNode()1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-
detachEvent() n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
elementFromPoint() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
execCommand() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
getElementById()1.5 1.55.0 5.06.0 6.05.0 5.0 5.0 5.0 n/a n/a1 1 n/a n/a-
getElementsByName()1.5 1.55.0 5.06.0 6.05.0 5.0 5.0 5.0 n/a n/a1 1 n/a n/aWarning
getElementsByTagName()1.5 1.55.0 5.06.0 6.05.0 5.0 n/a n/a n/a1 1 n/a n/a-
getSelection()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
handleEvent()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
mergeAttributes()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning
open()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning
queryCommandEnabled() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
queryCommandIndeterm() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
queryCommandState() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
queryCommandSupported() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
queryCommandText() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
queryCommandValue() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
recalc() n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
releaseEvents()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
routeEvent()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
write()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning
writeln()1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/a-

Event nameJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
onAfterUpdate n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onBeforeCut n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onBeforEditFocus1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a1 1 n/a n/aWarning
onBeforePaste n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onBeforeUpdate n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onClick1.0 1.01.0 1.02.0 2.03.02 3.023.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onContextMenu n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onCut n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onDblClick1.2 1.23.0 3.04.0 4.04.0 4.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onDrag n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onDragEnd n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onDragEnter n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onDragLeave n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onDragOver n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onDragStart n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onDrop n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onErrorUpdate n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onHelp n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
onKeyDown1.2 1.23.0 3.04.0 4.04.0 4.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onKeyPress1.2 1.23.0 3.04.0 4.04.0 4.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onKeyUp1.2 1.23.0 3.04.0 4.04.0 4.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onMouseDown1.2 1.23.0 3.04.0 4.04.0 4.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onMouseMove1.2 1.23.0 3.04.0 4.04.0 4.0 n/a n/a n/a n/a n/a4.0 4.0Warning
onMouseOut1.1 1.13.0 3.03.0 3.04.0 4.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onMouseOver1.0 1.01.0 1.02.0 2.03.0 3.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onMouseUp1.2 1.23.0 3.04.0 4.04.0 4.03.0 3.0 n/a n/a n/a n/a4.0 4.0Warning
onPaste n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onPropertyChange n/a5.0 5.0 n/a5.0 5.0 n/a n/a n/a n/a n/a n/a-
onReadyStateChange n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onRowEnter n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onRowExit n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onSelectStart n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
onStop1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-

Inheritance chain:

Element object, Node object