Document : Node
Return to: HTML DOM Level 2 index

Represents an HTML or XML document.

Platform Support

IE Mozilla Netscape Opera Safari
3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Constructors

Constructor Action IE Mozilla Netscape Opera Safari
Creates a new instance of a Document object.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Document() : Document

Creates a new instance of a Document object.

Returns
Document

Visibility
internal

Properties

Property Action IE Mozilla Netscape Opera Safari
activeElement : Element
Reference to the Element that currently has focus.
No Details 4.0+ no no no no
alinkColor : String
Specifies the color of active links.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Use the alink property of the tag to initially set the color of active links. To set this property, use the color properties of HTMLBodyElement to set the color in the tag.
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

anchors : Array
Array of all of the Anchor objects in a document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Because the Anchors array is read-only, modify the array by adding and deleting anchor elements. Do not confuse Anchors with hypertext links.
Availability

HTML DOM Level 1

applets : Array
Array of all of the Applet objects in a document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Remarks
Because the Applets array is read-only, modify the array by adding and deleting applet elements.
Availability

HTML DOM Level 1

bgColor : String
Background color of a document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Use the bgColor property of the tag to set the document background color. To set this bgColor, use the color properties of HTMLBodyElement to set the color at any time.
See Also

HTMLBodyElement

Availability

HTML DOM Level 1

body : Element
Reference to the body or frameset element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/document.html

Remarks

For additional compatibility information, see the quirksmode page:

http://www.quirksmode.org/viewport/compatibility.html

Availability

HTML DOM Level 1

charset : String
Character set of the document.
No Details 4.0+ no no no no
characterSet : String
Character set of the document.
No Details no 1.0+ 6.0+ no 1.0+
classes : Array
Array of style properties for CSS classes.
No Details no no 4.0+ no no
compatMode : Boolean
Indicates whether the document has standards-compliant mode turned on.
Show Details 6.0+ 1.75+ 7.0+ no no

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/compatmode_off.html

cookie : String
Value of the cookie that the browser has set for the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Availability

HTML DOM Level 1

defaultCharset : String
Default character set for the document.
No Details 4.0+ no no no no
designMode : String
Specifies that design mode for an HTML document is "on" or "off."
Show Details 5.0+ 1.4+ 7.0+ no no
Remarks
If design mode is on, a user can double-click the document to edit its HTML.
dir : String
Text direction of the content in the document.
Show Details 5.0+ 1.0+ 6.0+ no no

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/taginfo.html

Availability

HTML DOM Level 0

doctype : DocumentType
Document Data Type (DTD) associated with this document.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ no
Remarks
Every document can contain a Document Type Declaration (DTD) that defines document structure and entity references for the document. The doctype property represents the state of this document's DTD, which is either a DocumentType object, or null, if no DTD is specified.
Availability

HTML DOM Level 2|W3C

documentElement : Element
Root element in a document.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/document.html

Remarks

documentElement is a convenience property for accessing the contents of a document.

Without the

documentElement property, you would have to write doc.childNodes.item(0) or doc.childNodes[0] to access the contents of a document, instead of just typing doc.documentElement.

Availability

HTML DOM Level 2|W3C

domain : String
Internet domain of the document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Availability

HTML DOM Level 1

embeds : Array
Array of all embedded objects in the document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Remarks
embeds is a read-only property. You can add, delete, or modify the individual objects in the array, but you cannot modify the array itself.
See Also

Document.plugins

expando : Boolean
Indicates whether a client-side object may have instance properties added to it.
Show Details 4.0+ no no no no
Remarks
Use expando to help catch typos and case-sensitivity issues in your JavaScript.
fgColor : String
Font color of the document text.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Use the fgColor property of the <body> tag to initially set the color of the document text. To set this property, use the color properties of HTMLBodyElement to set the color in the <head> tag.
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

fileCreatedDate : String
Date that the document was created.
No Details 4.0+ no no no no
fileModifiedDate : String
Date that the document was last modified.
No Details 4.0+ no no no no
fileSize : Number
File size (in bytes) of the document.
No Details 4.0+ no no no no
forms : Array
Array of all of the Forms in the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Although the Forms array is read-only, you can modify the individual Form elements.
Availability

HTML DOM Level 1

frames : Array
Array of all of the Frames in the document.
Show Details 4.0+ no no no no
Remarks
Although the Frames array is read-only, you can modify the individual Frame elements.
height : Number
Height of the entire HTML document (in pixels).
No Details no 1.0+ 4.0+ 7.0+ 1.0+
ids : Array
Array of style properties in the document set by the Id attribute.
Show Details no no 4.0+ no no
Remarks
Although the Ids array is read-only, you can modify the individual Id elements.
images : Array
Array of Image objects in the document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Remarks
Although the Images array is read-only, you can modify the individual Image elements.
Availability

HTML DOM Level 1

Object that specifies whether or not and at what level the browser supports the specified feature.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+
Availability

HTML DOM Level 2|W3C

lastModified : String
Date that the document was last modified.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Availability

HTML DOM Level 0

layers : Array
Array of all of the Layer elements in the document.
Show Details no no 4.0+ no no
Remarks
Includes divs positioned by CSS.
linkColor : String
Color of the unvisited links in the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

links : Array
Array of all of the links in the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Although the Link array is read-only, you can modify the individual Link elements.
Availability

HTML DOM Level 1

location : Object
Complete URL of the document.
Show Details 3.0+ no 3-4 no no
Remarks
Deprecated for Window.location.
See Also

Window.location

media : String
The media that the document is intended for.
No Details 5.5+ no no no no
mimeType : String
Information about the document MIME type.
No Details 5.0+ no no no no
namespaces : Array
Array of the XML Namespaces for a document.
No Details 5.5+ no no no no
onactivate : Function
Fires when the element becomes active.
No Details 4.0+ no no no no
onbeforecut : Function
Fires immediately before the selection is cut to the clipboard.
No Details 4.0+ no no no 1.0+
onbeforedeactivate : Function
Fires immediately before the element stops being the active element.
No Details 4.0+ no no no no
onbeforeeditfocus : Function
Fires immediately before the element receives focus prior to being edited.
No Details 4.0+ no no no no
onbeforepaste : Function
Fires immediately before the selection is pasted from the clipboard to the element.
No Details 4.0+ no no no 1.0+
onclick : Function
Fires when the element is clicked.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
oncontextmenu : Function
Fires when the element is right-clicked and the context menu opens.
No Details 4.0+ no no no 1.0+
oncontrolselect : Function
Fires immediately before the element is selected.
No Details 4.0+ no no no no
oncut : Function
Fires when the element is cut to the clipboard.
No Details 4.0+ no no no 1.0+
ondblclick : Function
Fires when the element is double-clicked.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
ondrag : Function
Fires when the element is dragged.
No Details 4.0+ no no no 1.0+
ondragend : Function
Fires when the element is released from being dragged.
No Details 4.0+ no no no 1.0+
ondragenter : Function
Fires when the element has another object dragged onto it that can be dropped on the element.
No Details 4.0+ no no no 1.0+
ondragleave : Function
Fires when an element has an object dragged out of it that could be dropped onto the element.
No Details 4.0+ no no no 1.0+
ondragover : Function
Fires when an element has an object dragged over it that could be dropped onto the element.
No Details 4.0+ no no no 1.0+
ondragstart : Function
Fires immediately before an element is dragged.
No Details 4.0+ no no no 1.0+
ondrop : Function
Fires when an object is dropped onto the element.
No Details 4.0+ no no no 1.0+
onhelp : Function
Fires when a user presses the F1 key to activate help.
No Details 4.0+ no no no no
onkeydown : Function
Fires when a user presses down on a key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onkeypress : Function
Fires when a user presses a key or holds down the key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onkeyup : Function
Fires when a user releases a key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmousedown : Function
Fires when a user clicks down on the mouse button while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmousemove : Function
Fires when the mouse moves while the pointer over the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseout : Function
Fires when the mouse pointer moves off of the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseover : Function
Fires when the mouse pointer moves over the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseup : Function
Fires when the user releases the mouse button while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onpaste : Function
Fires when the clipboard contents are pasted onto the element.
No Details 4.0+ no no no 1.0+
onpropertychange : Function
Fires when one of the properties of the element changes.
No Details 4.0+ no no no no
onreadystatechange : Function
Fires when the ready state of the element changes.
No Details 4.0+ no no no no
onresize : Function
Fires immediately before an element is about to be resized.
No Details 4.0+ no no no 1.0+
onresizeend : Function
Fires when the element is finished being resized.
No Details 4.0+ no no no no
onresizestart : Function
Fires immediately before a user resizes the element.
No Details 4.0+ no no no no
onselectionchange : Function
Fires when the selected state of the document changes.
No Details 5.5+ no no no no
onstop : Function
Fires when a user clicks the Stop button on the browser.
No Details 5.5+ no no no no
parentWindow : Object
Reference to the parent Window of the document.
Show Details 4.0+ no no 8.0+ no

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/window.html

See Also

Window

plugins : Array
Array of plugins installed in the browser.
Show Details 2.0+ 1.0+ 1.0+ 7.0+ 1.0+
Remarks
Synonym for the embeds[] array.
See Also

Document.embeds

protocol : String
Full name of the protocol (not "http") used to retrieve the document.
Show Details 4.0+ no no no no
Remarks
IE only. Supported in IE4+.
referrer : String
URL of the referring document.
Show Details 2.0+ 1.0+ 1.0+ 7.0+ 1.0+
Remarks
If a user reaches the current document by clicking a link in another document, the referrer property holds the URL for the document with the link. If the user typed the URL into the address bar, the referrer property is an empty string.
Availability

HTML DOM Level 1

scripts : Array
Array of all of the Scripts in the document.
No Details 4.0+ no no no no
security : String
Information about the security certificate for the document.
No Details 5.5+ no no no no
selection : Object
Object representing any currently selected text.
No Details 4.0+ no no no no
styleSheets : Array
Array of all of the styleSheets in the document.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.2+
  • Safari: Cannot access disabled or alternate stylesheets.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/stylesheets.html

Availability

HTML DOM Level 2

tags : Array
Array of style properties for certain HTML tags.
No Details no no 4.0+ no no
title : String
Title of the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/innerhtml.html

Remarks
The title is the text that appears between the title tags of an HTML document.
Availability

HTML DOM Level 1

URL : String
URL of the document.
Show Details 4.0+ 1.0+ 2.0+ no no
See Also

location.href

URLUnencoded : String
URL-unencoded version of the URL.
Show Details 5.5+ no no no no
See Also

Document.URL

vlinkColor : String
Color of visited links.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Use the vlink property of the tag to initially set the color of visted links. To set this property, use the color properties of HTMLBodyElement to set the color in the tag.
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

width : Number
Width of the HTML document (in pixels).
No Details no 1.0+ 4.0+ 7.0+ 1.0+
XMLDocument : Object
Reference to the top-level node of the XML DOM used by the document.
No Details 5.0+ no no no no
XSLDocument : Object
Reference to the XSL document for the document.
No Details 5.0+ no no no no

Functions

Method Action IE Mozilla Netscape Opera Safari
captureEvents(Number eventMask) : void
Sets an document to capture the events specified by eventMask.
Show Details no no 4.0+ no no

Parameters
Number eventMask Bitmask containing the events to capture.

Returns
void

Remarks
Supported in Mozilla and NS4+.
See Also

releaseEvents

clear() : void
Clears the content from the document.
Show Details 3.0+ 1.0+ 2.0+ no 1.0+

Returns
void

close() : Object
Stops the output stream to the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Returns
Object

Availability

HTML DOM Level 0

contextual(String context) : void
Sets a concept to select tags to style.
Show Details no no 4.0 no no

Parameters
String context (one-or-more)Name of the context to be used.

Returns
void

static createAttribute(String name) : Attr
Creates a new Attr node
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • Safari: Safari will create the attribute, but you will have to use nodeValue to set its value.

Parameters
String name Name of the attribute to create.

Returns
Attr

Using createAttribute

var ele = document.createElement('a');
                        var href = document.createAttribute('href');
                        href.value = 'http://mozref.com';
                        ele.setAttributeNode(href);
                        ele.appendChild(document.createTextNode('Mozilla AOM Reference'));

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes3.html

Remarks

Although Attribute objects can only be bound to Element objects, they can be created by a Document object and later be bound to an element using setAttributeNode.

While an Attr node may contain several different properties, this method only populates the nodeName property and sets the attribute value set to null. The localName, prefix, and namespaceURI properties are all set to null. To set those values, use the createAttributeNS method.

Throws
Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
See Also

Attr|Element.setAttribute|Element.setAttributeNode

Availability

HTML DOM Level 2|W3C

static createAttributeNS(String namespaceURI, String qualifiedName) : Attr
Creates a new Attr using a namespace.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+

Parameters
String namespaceURI The namespace of the new attribute.
String qualifiedName The qualified name (e.g. rdf:about) of the attribute to create.

Returns
Attr

Remarks

Similar to createAttribute, createAttributeNS creates a new Attr within the current document, but createAttributeNS uses namespaces and can populate many of the attribute properties using the specified namespaceURI, qualifiedName objects.

This method will do its best to populate as many propertys as it can, to the best of its ability. For more information about these properties, please see their respective objects.

Throws
Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
Raises NAMESPACE_ERR error if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".
See Also

Attr

Availability

HTML DOM Level 2|W3C

createCDATASection(Object data) : CDATASection
Creates a new CDATASection node
Show Details no 1.0+ no no no

Parameters
Object data The text to wrap up into a new CDATASection object.

Returns
CDATASection

Using createCDATASection

var cdata = document.createCDATASection(
                        'this &p invalid markup &exists in this CDATA & section'
                        );
                        var obj = document.getElementById('header');
                        obj.appendChild(cdata);
Remarks
Creates a new CDATASection object within the current document, representing a region of uninterpreted content. Any text within this object, with the exception of the string "]]>", will not be encoded or otherwise interpreted by the DOM engine.
Throws
Raises a NOT_SUPPORTED_ERR error if the current document is an HTML document.
Availability

HTML DOM Level 2|W3C