files/en-us/web/api/domimplementation/createdocument/index.md
{{ApiRef("DOM")}}
The DOMImplementation.createDocument() method creates and
returns an {{domxref("XMLDocument")}}.
createDocument(namespaceURI, qualifiedName)
createDocument(namespaceURI, qualifiedName, documentType)
namespaceURI
null if the document doesn't belong to one.qualifiedName
null value is treated the same as the empty string ("").documentType {{optional_inline}}
null.The newly-created {{domxref("XMLDocument")}}.
const doc = document.implementation.createDocument(
"http://www.w3.org/1999/xhtml",
"html",
null,
);
const body = document.createElementNS("http://www.w3.org/1999/xhtml", "body");
body.setAttribute("id", "abc");
doc.documentElement.appendChild(body);
alert(doc.getElementById("abc")); // [object HTMLBodyElement]
{{Specifications}}
{{Compat}}