HTML | DOM adoptNode() Method

This DOM adoptNode() method is used to adopt a node from another document. All node types, can be adopted. All child nodes along with the original node can be adopted. AdoptNode() method is used to return node objects.

Syntax:

document.adoptNode(node)

Perameter Value: DOM adoptNode() method contain only one method described below.



  • node: Any type of node is required.

Return Value: It returns a node object, representing the adopted node.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <h1><center>Geeks 
<button onclick="adopt()">Press</button>
</center> </h1>
  
        <h4>Clicking on the 'Press' button 
will showcase adopt() method</h4>
  
    <p id="gfg">
  
        <iframe 
        </iframe>
  
    </p>
    <script>
        function adopt() {
            var frame = 
              document.getElementsByTagName(
                "iframe")[0];
            
            var h = 
    frame.contentWindow.document.getElementsByTagName(
                "button")[0];
            
            // 'h' is button type adopted node.
            var x = document.adoptNode(h);
            document.body.appendChild(x);
        }
    </script>
  
</body>
  
</html>

chevron_right


Output:
Before pressing the button:

After pressing the button:

Note: All child nodes are adopted.

Browser Support: The browsers support by DOM adoptNode() method are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : ManasChhabra2



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.