HTML DOM createDocumentType() Method

The DOMImplementation createDocumentType() method returns a Doctype object which can either be used with DOMImplementation createDocument() method for document creation or can be put into the document.

Syntax:

var doctype = document.implementation.createDocumentType(qualifiedNameStr, publicId, systemId);

Parameters:

  • qualifiedNameStr: It is a DOMString containing the qualified name
  • publicId: It is a DOMString containing the PUBLIC identifier.
  • systemId: It is a DOMString containing the SYSTEM identifiers.

Return Value: This function returns DOMDocumentType node.



Example: In this example, we will create a document type using this method.

filter_none

edit
close

play_arrow

link
brightness_4
code

</html>
<!DOCTYPE HTML> 
<html>  
<head>
    <meta charset="UTF-8">
    <title>createDocumentType() method</title>
</head>   
  
<body style="text-align:center;">
    <h1 style="color:green;">  
     GeeksforGeeks
    </h1
    <p id="a"
    HTML | DOM createDocumentType() method
    </p>
  
    <button onclick = "Geeks()">
    Click Here
    </button>
    <script
        function Geeks(){
            var dt = 
document.implementation.createDocumentType(
'svg:svg', null, 
            console.log(dt);
            var doc = document.implementation.createDocument (
            var head = document.createElementNS(
            head.setAttribute('id', 'headDoc');
            doc.documentElement.appendChild(head);
            var body = document.createElementNS(
            body.setAttribute('id', 'bodyDoc');
            doc.documentElement.appendChild(body);
            console.log(doc);
        }
  </script
</body>   
</html>

chevron_right


Output:

Before Button Click:

After Button Click: Created document and the doctype can be seen in the console.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.