DOMImplementation.createDocument()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

O método DOMImplementation.createDocument() cria e retorna um XMLDocument.

Sintaxe

doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, documentType);

Parâmetros

namespaceURI

É um DOMString contendo a URI do namespace do documento que será criado, ou null se o documento não pertencer a nenhum.

qualifiedNameStr

Is a DOMString containing the qualified name, that is an optional prefix and colon plus the local root element name, of the document to be created.

documentType Optional

Is the DocumentType of the document to be created. It defaults to null.

Example

js
var doc = document.implementation.createDocument(
  "https://www.w3.org/1999/xhtml",
  "html",
  null,
);
var body = document.createElementNS("https://www.w3.org/1999/xhtml", "body");
body.setAttribute("id", "abc");
doc.documentElement.appendChild(body);
alert(doc.getElementById("abc")); // [object HTMLBodyElement]

Especificações

Specification
DOM
# ref-for-dom-domimplementation-createdocument②

Compatibilidade com navegadores

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
createDocument

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also