HTML DOMドキュメントimportNode()
例
iframe(別のドキュメント)から最初の<h1>要素をインポートします。
const frame = document.getElementsById("myFrame");
const h1 = frame.contentWindow.document.getElementsByTagName("H1")[0];
const node = document.importNode(h1, true);
定義と使用法
このimportNode()
メソッドは、別のドキュメントからノードをインポートします。
2番目のパラメーターをに設定するとtrue
、子ノードもインポートされます。
ノート
インポートされたノードは元のドキュメントから削除されません。
インポートされたノードは、元のノードのコピーです。
関連項目:
構文
document.importNode(node, deep)
パラメーター
Parameter | Description |
node | Required. A node from another document. Can be type of node. |
deep | Required.false : only the node itself is imported.true : child nodes (descendants) are also imported. |
戻り値
タイプ | 説明 |
ノード | インポートされたノード。 |
ブラウザのサポート
document.importNode()
DOMレベル2(2001)の機能です。
すべてのブラウザで完全にサポートされています。
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |