You are here: Reference > JavaScript > client-side > HTML DOM > methods > createDocumentType (implementation)

createDocumentType method (implementation)

Browser support:
Creates a new doctype object.
Note: The createDocumentType method is supported in Internet Explorer from version 9.
When the new doctype object is created, it can be used for the createDocument method to specify the document type for a new XML document or it can be inserted into an XML document with the insertBefore or replaceChild method.


object.createDocumentType (qualifiedName, publicID, systemID);
You can find the related objects in the Supported by objects section below.


Required. String that specifies the name of the document type.
Required. String that specifies the public identifier for the document type element.
Required. String that specifies the system identifier for the document type element.

Return value:

Returns the newly created doctype object.

Example HTML code 1:

This example illustrates the use of the createDocumentType method:
    <script type="text/javascript">
        function CreateXMLDoc () {
            if (document.implementation.createDocument && 
                var fruitDocType = document.implementation.createDocumentType ("fruit", "SYSTEM", "<!ENTITY tf 'tropical fruit'>");
                var xmlDoc = document.implementation.createDocument ("", "fruits", fruitDocType);

                var fruitNode = xmlDoc.createElement ("fruit");
                fruitNode.setAttribute ("name" , "avocado");
                xmlDoc.documentElement.appendChild (fruitNode);
                var serializer = new XMLSerializer();
                alert (serializer.serializeToString (xmlDoc));
            else {
                alert ("Your browser does not support this example");

    <button onclick="CreateXMLDoc ();">Create an XML document with document type!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content