DOMImplementation: createDocument() メソッド
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 Standard # ref-for-dom-domimplementation-createdocument② |
ブラウザーの互換性
BCD tables only load in the browser
関連情報
- 所属先の
DOMImplementationインターフェイス