The importNode()
method imports a node from another document.
importNode |
Yes | 9.0 | Yes | Yes | Yes |
document.importNode(node, deep);
Parameter | Type | Description |
---|---|---|
node | Node | Required. Node to import |
deep | Boolean | Required. If set to false, only the node itself is imported, if set to true, all child nodes are also imported |
The imported node in Node object type.
The following code shows how to return the first H1 element in an iframe.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">test</button> <script> function myFunction() { var frame=document.getElementsByTagName("iframe")[0] var h=frame.contentWindow.document.getElementsByTagName("h1")[0]; var x=document.importNode(h,true); document.getElementById("demo").appendChild(x); } </script> <iframe src="http://example.com" style="height:280px;width:420px;"></iframe> </body> </html>