Definition and Usage..
The importNode() method imports a node from another document.
The imported node can be of all node types.
If the second parameter is set to true, the nodes's child nodes (descendants) will also be imported.
Note: The original node is not removed from the other document. The imported node is a copy of the original
Syntax: node.appendChild(node)
Different way to how to declare importNode() in program.
<!DOCTYPE html>
<html>
<body>
<iframe src="XYZ.html" style="height:380px;width:520px;"></iframe>
<p>Click the "Try it" button to get 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 importNode() 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.importNode(h, true);
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 get 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 importNode() 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.importNode(h, true);
document.body.appendChild(x);
}
</script>
</body>
</html>
Comments
Post a Comment