Adopt the first <h1> element that appears in an iframe (another document):
const frame = document.getElementById("myFrame");
const h1 = frame.contentWindow.document.getElementsByTagName("H1")[0];
const node = document.adoptNode(h1);
Try it Yourself »
The adoptNode()
method adopts a node from another document.
The adopted node can be of all types.
Any child nodes (descendants) of the adopted node, are also adopted.
The original node (with child nodes) is removed from the other document.
document.adoptNode(
node)
Parameter | Description |
node | Required. A node from another document. Can be of any node type. |
Type | Description |
Node | The adopted node. |
document.adoptNode
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!