Javascript examples for DOM:Document adoptNode
The adoptNode() method adopts a node from another document and removes the original node and its child nodes from the other document.
Parameter | Type | Description |
---|---|---|
node? | Node object | Required. The node from another document. Can be of any node type |
A Node object, representing the adopted node
The following code shows how to Adopt the first <h1> element that appears in an iframe
<!DOCTYPE html> <html> <body> <iframe src="http://java2s.com" style="height:380px;width:520px;"></iframe> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from ww w .j a va2s . c o m*/ var frame = document.getElementsByTagName("IFRAME")[0] var h = frame.contentWindow.document.getElementsByTagName("H1")[0]; var x = document.adoptNode(h); document.body.appendChild(x); } </script> </body> </html>