createDocumentType (W3C DOM Core method)

Spec
Version Depr. Static
DOM2 No No
Browser support (more…)
IE7 FF1.5+ SA2+ OP9+
None Full Full Full
Returns
DocumentType
Throws
INVALID_CHARACTER_ERR, NAMESPACE_ERR

Example

var doctype = document.implementation.createDocumentType(
    'html',
    '-//W3C//DTD XHTML 1.0 Strict//EN',
    'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
);

var dom = document.implementation.createDocument
    ('http://www.w3.org/1999/xhtml', 'html', doctype);

The example above creates a DocumentType for XHTML 1.0 Strict, then passes it as the doctype argument to createDocument. That operation would create this skeleton document:

<!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"></html>

Arguments

name (DOMString) required

The qualified name 1 of the document type to be created.

publicId (DOMString) required

The public identifier of this document type.

systemId (DOMString) required

The system identifier of this document type.

Description

Create an empty DocumentType node.

Entity declarations and notations are not made available, and entity reference expansions and default attribute additions don't occur. A created DocumentType has a null ownerDocument, until it's associated with a Document; the doctype cannot be appended to an existing document, it must be passed as the doctype argument to createDocument.

The DOM does not currently specify any way of populating the created node — additional entities and notations cannot be added.

Return value

The created document type

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
None None None Full Full Full Buggy Full Full Full Full
DANGER: Crash bug in Safari 1.3

In Safari 1.3 this method crashes the browser, whatever the circumstances of its use.

Internet Explorer doesn't implement this method (it returns undefined; in Internet Explorer 5.5 in HTML the implementation object itself is undefined).

Footnotes

1 A qualified name is comprised of a local name, plus an optional prefix delimited with a colon, for example svg:rect.

User-contributed notes

There are no comments yet.

Related Products