--- title: DOMImplementation.createDocument() slug: Web/API/DOMImplementation/createDocument translation_of: Web/API/DOMImplementation/createDocument ---
{{ApiRef("DOM")}}
O método DOMImplementation.createDocument()
cria e retorna um {{domxref("XMLDocument")}}.
doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, documentType);
null
se o documento não pertencer a nenhum.Is the {{domxref("DocumentType")}} of the document to be created. It defaults to null
.
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', 'abc'); doc.documentElement.appendChild(body); alert(doc.getElementById('abc')); // [object HTMLBodyElement]
Specification | Status | Comment |
---|---|---|
{{SpecName('DOM WHATWG', '#dom-domimplementation-createdocument', 'DOMImplementation.createDocument')}} | {{Spec2('DOM WHATWG')}} | Modified the return type of createDocument() from {{domxref("Document")}} to {{domxref("XMLDocument")}}.The third argument of createDocument() , doctype, is now optional and default to null . |
{{SpecName('DOM3 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}} | {{Spec2('DOM3 Core')}} | No change from {{SpecName("DOM2 Core")}} |
{{SpecName('DOM2 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}} | {{Spec2('DOM2 Core')}} | Initial definition. |
{{Compat("api.DOMImplementation.createDocument")}}