HTML DOM createDocument() Method
Last Updated :
12 Jul, 2022
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.
html
<!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 1
- Edge 12
- Firefox 1
- Safari 1
- Opera 12.1
- Internet Explorer 9
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...