Skip to content
Related Articles

Related Articles

Improve Article
HTML DOM createDocument() Method
  • Last Updated : 24 Jul, 2020

The DOMImplementation createDocument() method is used to create and return a Document.

Syntax:

var doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, docType);

parameters:

  • namespaceURI: It is a DOMString containing the namespace URI of the document to be created, or null if the document doesn’t belong to one.
  • qualifiedNameStr: It is a DOMString containing the qualified name
  • docType (Optional): It Is the Document type of the document to be created, the default value is null.

Return Value: This function returns DOMDocument object on success.

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






<!DOCTYPE HTML> 
<html>  
<head>
    <meta charset="UTF-8">
    <title>createDocument() method</title>
</head>   
  
<body style="text-align:center;">
    <h1 style="color:green;">  
     GeeksforGeeks
    </h1
    <p id="a"
    HTML | DOM createDocument() method
    </p>
  
    <button onclick = "Geeks()">
    Click Here
    </button>
    <script
        function Geeks(){
            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:

Supported Browsers:

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :