DOM - DOMImplementation Object Method - createdocument


The method createDocument () is used to create a DOM Document object of the specified type with its document element.


Following is the syntax of the createDocument () method.

Document doc = document.implementation.createDocument
   (namespaceURI, qualifiedNameStr, documentType);
  • namespaceURI is the namespace URI of the document element to be created or null.

  • qualifiedName is the qualified name of the document element to be created or null.

  • doctype is the type of document to be created or null.

  • This method returns a new Document object with its document element.


Following example demonstrates the usage of the createDocument () method −

<!DOCTYPE html>
         var doc = document.implementation.createDocument ('', 
            'html', null);
         var body = document.createElementNS('', 'body');
         body.setAttribute('id', 'Company');
         document.write(doc.getElementById('Company')); // [object HTMLBodyElement]


Save this file as domimplementation_createdocument.htm on the server path (this file and node.xml should be on the same path in your server). We will get the output as shown below −

[object HTMLBodyElement]