1. 開発者向けのウェブ技術
  2. Web API
  3. DOMImplementation
  4. DOMImplementation: createDocument() メソッド

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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-createdocument2

ブラウザーの互換性

関連情報

MDN の改良に協力

協力方法を知る

このページは MDN の貢献者によって に最終更新されました。

AltStyle によって変換されたページ (->オリジナル) /