English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
adoptNode()The method adopts a node from another document.
If all child nodes (descendants) of the adopted node (if any) will also be adopted.
The adopted node and its child nodes will be removed from its original document.
Usingdocument.importNode()method to copy a node from another document without deleting it.
You can also use element.cloneNode()The method copies a node from the current document without deleting it.
document.adoptNode(externalNode)
var iframe = document.querySelector()39;iframe'); var iframeImages = iframe.contentDocument.querySelectorAll('h2'); var newParent = document.getElementById('result'); iframeImages.forEach(function(elem) { newParent.appendChild(document.adoptNode(elem)); });Test See‹/›
All browsers fully support the acceptNode() method:
Method | |||||
adoptNode() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
externalNode | A node from another document will be adopted |
Return Value: | Represents the Node object of the adopted node |
---|---|
DOM Version: | DOM Level3 |