DocumentType (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">
The
example above shows a doctype for XHTML 1.0
Strict. Its name is
html, its publicId is
-//W3C//DTD XHTML 1.0 Strict//EN and its systemId is
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd. This
example has no internalSubset (the
property would return an empty string).
An internal subset is when additional items are defined as a subset inside the main DTD, for example, adding custom attributes to XHTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
[
<!ATTLIST input validate CDATA #IMPLIED>
<!ATTLIST input range CDATA #IMPLIED>
]>
We can retrieve the DocumentType
object for a page using the doctype property:
var dtd = document.doctype;
Description
The
DocumentType interface inherits from Node, and provides access to the attributes of a Document
Type Declaration (DTD).
Every Document has a
doctype property, which is a read-only
instance of this interface where available, otherwise
null. It should only return an object for an XML
document that has a Document Type Declaration; for HTML documents, or XML
documents without a DTD, it should be null.
A
DocumentType node cannot have children.
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 in XML does not implement the internalSubset, publicId or systemId properties (they return undefined).
Internet Explorer 5.5 in HTML does not
implement this interface (doctype is
undefined).
In Internet Explorer 6 and 7
and Safari 1.3 and 2 in HTML mode1, the doctype property returns null.
However this is according to specification — the doctype should only return an object in XML
(including XHTML mode2), otherwise it should be null.
In
Safari 1.3 and 2 in XHTML mode or XML the doctype property is available, but all its
properties are null.
The relationship between
the DocumentType node and its owning Document varies between browsers. While all which implement
this interface have the correct ownerDocument,
only Firefox has the document as its parentNode; in Opera and Safari
3 both properties are null.
(Firefox has the correct behavior.)
Only
Internet Explorer in XML and Opera
in XHTML mode or XML return populated entities or notations collections. In Internet
Explorer in XML the entities collection only includes internal
entities (those defined in a doctype's internal subset).
Only
Firefox in XHTML mode or XML and
Opera in XHTML mode provide data for the internalSubset property; in
Safari it's null, in
Internet Explorer it's undefined, otherwise
it's an empty string.
Firefox 3 and
Safari 1.3 and 2 have bugs in their
implementation of the name property.
Only Firefox, Safari
3 and Opera are able to retrieve
the publicId or systemId of a doctype.
In this Section
entities
An unordered list of the general entities declared in the DTD.internalSubset
A string containing the text of a DTD's internal subset.name
The name of aDocumentTypenode.notations
An unordered list of the notations declared in the DTDpublicId
The public identifier of aDocumentType.systemId
The system identifier of aDocumentType.
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.