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.


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


  • 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.

    <meta charset="UTF-8">
    <title>createDocument() method</title>
<body style="text-align:center;">
    <h1 style="color:green;">  
    <p id="a"
    HTML | DOM createDocument() method
    <button onclick = "Geeks()">
    Click Here
        function Geeks(){
            var doc = document.implementation.createDocument (
            var head = document.createElementNS(
            head.setAttribute('id', 'headDoc');
            var body = document.createElementNS(
            body.setAttribute('id', 'bodyDoc');


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 :