Javascript examples for DOM:Document importNode
The importNode() method imports a node from another document.
The original node is not removed from the other document.
The imported node is a copy of the original.
document.importNode(node, deep);
Parameter | Type | Description |
---|---|---|
node? | Node object | Required. The node from another document. |
deep | Boolean | Required. If set to false, only the node itself is imported, if set to true, all child nodes are also imported |
A Node object, representing the imported node
The following code shows how to return the first <h1> element that appears in an iframe (another document):
<!DOCTYPE html> <html> <body> <iframe src="http://java2s.com" style="height:380px;width:520px;"></iframe> <button onclick="myFunction()">Test</button> <script> function myFunction() {/* w ww . j av a 2 s. c o m*/ var frame = document.getElementsByTagName("IFRAME")[0] var h = frame.contentWindow.document.getElementsByTagName("H1")[0]; var x = document.importNode(h, true); document.body.appendChild(x); } </script> </body> </html>