HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> iframe{ height:280px; width:320px; display:block; margin-bottom:10px; } </style> </head> <body> <iframe src="/js/document-adoptnode/iframe"></iframe> <p><strong>Note:</strong> Click on the button to adopt h1 node from iframe.</p> <button onclick="myFunction()">Click me</button> <script> var frame = document.getElementsByTagName("iframe")[0]; function myFunction(){ //Try to change "h1" to "p" var get = frame.contentWindow.document.getElementsByTagName("h1")[0]; var x = document.adoptNode(get); document.body.appendChild(x); } </script> </body> </html>
OUTPUT
×

Save as Private