Document (W3C DOM Core object)
| Version | Depr. | Parent |
|---|---|---|
| DOM1 | No | Node |
| 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
- createAttribute
Creates an Attr node with the specified name. - createAttributeNS
Creates an Attr node with the specified name and namespaceURI. - createCDATASection
Creates a CDATASection node in an XML document, with the specified string data. - createComment
Creates a Comment node with the specified string value. - createDocumentFragment
Creates an empty DocumentFragment node. - createElement
Creates an Element node of the specified type; if the element has default attributes in this document type, those attributes are automatically created and attached to the element. - createElementNS
Creates an Element node of the specified type and namespaceURI; if the element has default attributes in this document type, those attributes are automatically created and attached to the element. - createEntityReference
Create an EntityReference node in an XML document, of the specified name. - createProcessingInstruction
Creates a ProcessingInstruction node in an XML document, with the specified name and string data. - createTextNode
Creates a Text node with the specified string value. - doctype
The Document Type Declaration of an XML document. - documentElement
A shortcut property that refers to the document's root element. - getElementById
Returns the Element node with the specified ID. - getElementsByTagName
Retrieves an ordered list of all elements with a given tag name, that are descendents of this document or element, in the linear order in which they appear in the DOM tree. - getElementsByTagNameNS
Retrieves an ordered list of all elements with a given localName and namespaceURI, that are descendents of this document or element, in the linear order in which they appear in the DOM tree. - implementation
The DOMImplementation object that controls this document. - importNode
Imports a node from another document into this one, optionally including all its children.
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
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.