HTML DOM adoptNode() method
Example
Get the first H1 element in the iframe and insert it into the current document:
var
frame
=
document
.
getElementsByTagName
(
"
IFRAME
"
)
[
0
]
var
h
=
frame
.
contentWindow
.
document
.
getElementsByTagName
(
"
H1
"
)
[
0
]
;
var
x
=
document
.
adoptNode
(
h
)
;
Try it »
Definition and usage
The adoptNode() method is used to get a node from another document.
The node can be of any node type.
Note: All child nodes under the node will also be obtained.
Note: The node and its child nodes will be removed from the source document.
Tip: Use document.importNode() method to copy a node, but the node in the original document is not deleted.
Tip: Use element.cloneNode() method to copy a node of the current document, and the node will not be deleted.
Browser support
The numbers in the table indicate the first browser version that supports this method.
| Method | |||||
|---|---|---|---|---|---|
| adoptNode() | Yes | 9.0 | 3.0 | Yes | 9.0 |
Syntax
document.adoptNode(node)
Parameter value
| Parameters | Type | Description |
|---|---|---|
| node | Node object | Required. A node from another document, which can be of any node type. |
Technical Details
| DOM version: | Core Level 3 Document Object |
|---|---|
| Return Value: | Node object, representing the obtained node |
Document Object