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.

DOMImplementation.createDocument() メソッドは、 XMLDocument を作成して返します。

構文

js
createDocument(namespaceURI, qualifiedNameStr)
createDocument(namespaceURI, qualifiedNameStr, documentType)

引数

namespaceURI

作成する文書の名前空間 URI を格納した文字列です。文書が名前空間に属さない場合は null です。

qualifiedNameStr

作成する文書の修飾名(オプションで接頭辞とコロンにローカルルート要素名を加えたもの)を格納した文字列です。

documentType 省略可

作成する文書の DocumentType です。既定値は null です。

返値

なし (undefined)。

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]

仕様書

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

ブラウザーの互換性

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

関連情報