Sunday, May 17, 2026
HomeLanguagesJavascriptHTML DOM createDocumentType() Method

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.

html




</html>
<!DOCTYPE HTML>
<html> 
<head>
    <meta charset="UTF-8">
    <title>createDocumentType() method</title>
</head>  
 
<body style="text-align:center;">
    <h1 style="color:green;"> 
     neveropen
    </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>


Output:

Before Button Click:

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

Supported Browsers:

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Safari 1
  • Opera 12.1
  • Internet Explorer 9
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS