THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML DOM importNode() Method

Document Object Reference Document Object

Example

Return the first <h1> element that appears in an iframe (another document):

var frame = document.getElementsByTagName("iframe")[0]
var h = frame.contentWindow.document.getElementsByTagName("H1")[0];
var x = document.importNode(h, true);
Try it Yourself »

Definition and Usage

The importNode() method imports a node from another document.

The imported node can be of all node types.

If the second parameter is set to true, the nodes's child nodes (descendants) will also be imported.

Note: The original node is not removed from the other document. The imported node is a copy of the original.

Tip: Use the document.adoptNode() method to remove and import a node from another document.

Tip: Use the element.cloneNode() method to copy a node from the current document.


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method
importNode() Yes 9.0 1.0 Yes 9.0

Syntax

document.importNode(node,deep)

Parameter Values

Parameter Type Description
node  Node object Required. The node from another document. Can be of any node type
deep Boolean Required. If set to false, only the node itself is imported, if set to true, all child nodes (descendants) are also imported

Technical Details

Return Value: A Node object, representing the imported node
DOM Version Core Level 2 Document Object

Document Object Reference Document Object