Definition and Usage..
The adoptNode() method adopts a node from another document.
The adopted node can be of all node types.
Note: All child nodes (descendants), if any, of the adopted node, are also adopted.
Note: The original node (and its child nodes, if any) is removed from the other document.
Tip: Use the document.importNode() method to copy a node, without removing it, from another document.
Tip: Use the element.cloneNode() method to copy a node, without removing it, from the current document
Syntax: node.appendChild(node)
Different way to how to declare adoptNode() Method in program.
<!DOCTYPE html>
<html>
<body>
<iframe src="XYZ.html" style="height:380px;width:520px;"></iframe>
<p>Click the "Try it" button to adopt and display the value of the first H1 element in the iframe (another document).</p>
<p><strong>Note:</strong> Internet explorer 8 and earlier does not support the adoptNode() method.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var frame = document.getElementsByTagName("IFRAME")[0]
var h = frame.contentWindow.document.getElementsByTagName("HTML")[0];
var x = document.adoptNode(h);
document.body.appendChild(x);
}
</script>
</body>
</html>
<html>
<body>
<iframe src="XYZ.html" style="height:380px;width:520px;"></iframe>
<p>Click the "Try it" button to adopt and display the value of the first H1 element in the iframe (another document).</p>
<p><strong>Note:</strong> Internet explorer 8 and earlier does not support the adoptNode() method.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var frame = document.getElementsByTagName("IFRAME")[0]
var h = frame.contentWindow.document.getElementsByTagName("HTML")[0];
var x = document.adoptNode(h);
document.body.appendChild(x);
}
</script>
</body>
</html>
Comments
Post a Comment