HTML DOM Document importNode()
Example
Import the first <h1> element from an iframe (another document):
const frame = document.getElementsById("myFrame");
const h1 = frame.contentWindow.document.getElementsByTagName("H1")[0];
const node = document.importNode(h1, true);
Try it Yourself »
Definition and Usage
The importNode()
method imports a node from another document.
With the second parameter set to true
, child nodes will also be imported.
Note
The imported node is not removed from the original document.
The imported node is a copy of the original.
See Also:
Syntax
document.importNode(node, deep)
Parameters
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. |
Return Value
Type | Description |
Node | The imported node. |
Browser Support
document.importNode()
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |