Document.adoptNode() - HTML - JS method

Asked

Viewed 15 times

1

I need to develop a page that shows how the adoptNode() method works, so what I read basically removes a node from an external page and uploads it to the current document. This is my code, but the H1 tag element is not loaded to the current page:

<html>
<body>
<!-- Carrega página com um elemento de tag H1  -->
<iframe src="ex2.html" style="height:380px;width:520px;"></iframe> 

<button onclick="myFunction()">Try it</button>

   

<script>
function myFunction() {
    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>

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.