HTML DOM importNode()Method

Document 对象参考手册Document Object

Examples

Return the first H1 element in the iframe:

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 copies a node from another document to this document for use.

The imported node can be any node type.

If the second value is set totrue, then all descendant nodes of the node are also copied.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the importNode() method

Note:Internet Explorer 8 and earlier versions of IE do not support this method.


Syntax

document.importNode(node,deep)

Parameters

Parameter Type Description
deep Boolean Required. If true, also recursively copy all descendant nodes of the importedNode node.

Return Value

Type Description
Node object The imported node

Technical Details

DOM Version Core Level 2 Document Object


Document 对象参考手册Document Object

Other Extensions