Range: createContextualFragment() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
Range.createContextualFragment()
メソッドは、範囲の先頭ノード(選択されたノードの親)をコンテキストノードとして、 HTML フラグメント構文解析アルゴリズムまたは XML フラグメント構文解析アルゴリズムを呼び出して DocumentFragment
を返します。 HTML フラグメント解釈アルゴリズムは、範囲が HTMLness ビットが設定された Document
に属している場合に使用します。 HTML では、コンテキストノードが html
である場合、歴史的な理由から、フラグメント解釈アルゴリズムは body
をコンテキストとして呼び出されます。
構文
js
createContextualFragment(tagString)
引数
-
文書フラグメントに変換するテキストとタグを格納するテキストです。
返値
DocumentFragment
オブジェクトです。
例
js
const tagString = "<div>I am a div node</div>";
const range = document.createRange();
// 文書内の最初の div の親をコンテキストノードにします。
range.selectNode(document.getElementsByTagName("div").item(0));
const documentFragment = range.createContextualFragment(tagString);
document.body.appendChild(documentFragment);
仕様書
Specification |
---|
HTML # dom-range-createcontextualfragment |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createContextualFragment |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.