DOMImplementation: createDocument() メソッド
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
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]
仕様書
| 仕様書 |
|---|
| DOM> # ref-for-dom-domimplementation-createdocument②> |
ブラウザーの互換性
関連情報
- 所属先の
DOMImplementationインターフェイス