Document (W3C DOM Core object)

Spec
Version Depr. Parent
DOM1 No Node
Browser support (more…)
IE5.5+ FF1.5+ SA1.3+ OP9+
Buggy Buggy Buggy Buggy

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
  <title>IM IN UR DOCUMENT</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<body>
  <h1>OH NODES!</h1>
</body>
</html>

The example above shows a complete HTML page; the whole page is a single Document node, whose documentElement is <html>.

Description

The Document interface inherits from Node, and represents the whole document, such as an HTML page. Although the Document node is conceptually the root of a document, it isn't physically the root - the root node is the first Element node in the Document, and is represented by its documentElement property.

A Document node may have a single Element and DocumentType node as child nodes, and any number of ProcessingInstruction and Comment nodes.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy Buggy

Internet Explorer doesn't implement the following:

And Internet Explorer in HTML doesn't implement the following (but does in XML):

Additionally, Internet Explorer 5.5 in HTML doesn't implement the following (but does in XML):

Opera doesn't implement the following:

Internet Explorer has a buggy implementation of getElementById. Internet Explorer, Safari and Opera have additional features in their implementation of getElementById.

Internet Explorer in HTML has a buggy implementation of createElement. They also see the DTD as a Comment node1 (and the doctype property is null).

Internet Explorer 6 and 7 don't inherit the normalize method from Node, and have only a partial implementation of the implementation property.

Internet Explorer 5.5 in HTML doesn't see the document as a node at all; although a subset of its specialized properties and methods are available (all apart from the exceptions listed above), it doesn't inherit any properties or methods from Node, apart from the childNodes collection. It also doesn't support the * collection (all elements) of getElementsByTagName, and doesn't implement the implementation property.

Firefox does implement the createEntityReference method, but it returns null.

In Safari 1.3 and 2 in HTML mode2 the createEntityReference method works, when it should throw an exception.

Safari 1.3 and 2, Firefox and Opera have buggy implementations of createAttributeNS.

Safari, Firefox and Opera have buggy implementations of createElementNS.

Safari, Firefox 1.5 and 2 and Opera have buggy implementations of getElementsByTagName and importNode.

Safari 1.3 and 2 have only a partial implementation of getElementsByTagNameNS.

Safari 1.3 and 2 and Opera have buggy implementations of createCDATASection and createProcessingInstruction.

Opera in HTML mode or XML3 and Safari at all times don't see the DTD as a child node of the Document — it doesn't appear in the document's childNodes collection, and the parentNode of the DocumentType object is null (except in Safari 1.3 and 2 in HTML mode, in which doctype itself is null).

All browsers have incomplete or buggy implementations of the doctype property.

In this Section

Footnotes

1 IE6 ignores the first two characters DO in DOCTYPE, as though the first two characters after "<!" are assumed to have been "--", like a normal comment, even though they weren't. Likewise the last two characters, d" from the DTD URI are also missing.

2 On XHTML or HTML pages served as text/html.

3 On XHTML or HTML pages served as text/html.

User-contributed notes

Related Products