DOM - DOMImplementation Object Method - createdocument


Advertisements


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

Syntax

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.

Example

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

<!DOCTYPE html>
<html>
   <body>
      <script>
         var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 
            'html', null);
         var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
         body.setAttribute('id', 'Company');
         doc.documentElement.appendChild(body);
         document.write(doc.getElementById('Company')); // [object HTMLBodyElement]
      </script>
   </body>
</html>

Execution

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]

dom_domimplementation_object.htm

Advertisements