DOMImplementation: createDocument()-Methode

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.

Die DOMImplementation.createDocument()-Methode erstellt und gibt ein XMLDocument zurück.

Syntax

js
createDocument(namespaceURI, qualifiedName)
createDocument(namespaceURI, qualifiedName, documentType)

Parameter

namespaceURI

Ein String, der den Namespace-URI des zu erstellenden Dokuments enthält, oder null, wenn das Dokument zu keinem Namespace gehört.

qualifiedName

Ein String, der den qualifizierten Namen enthält, also ein optionales Präfix und ein Doppelpunkt sowie den lokalen Namen des Root-Elements des zu erstellenden Dokuments. Ein null-Wert wird wie ein leerer String ("") behandelt.

documentType Optional

Der DocumentType des zu erstellenden Dokuments. Standardmäßig null.

Rückgabewert

Das neu erstellte XMLDocument.

Beispiele

js
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]

Spezifikationen

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

Browser-Kompatibilität

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

Siehe auch