HTML DOM adoptNode() Method
Last Updated :
13 Jun, 2023
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)
Parameter Value: DOM adoptNode() method contains only one method described below.
- node: Any type of node is required.
Return Value: It returns a node object, representing the adopted node.
Example:
HTML
<!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 >
|
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 1
- Edge 12
- Internet Explorer 9
- Firefox 1
- Opera 12.1
- Safari 3
Share your thoughts in the comments
Please Login to comment...