Cria uma cópia de um nó a partir de um documento externo para ser inserido no document atual.


var node = document.importNode(externalNode, deep);
O novo nó que será importado no documento. A propriedade parentNode do novo nó é null, desde que ele não foi inserido na árvores do documento.
O nó de outro documento para ser importado.
Um boolean, indicando se os nós filhos, do nó a ser importado, devem ser importados também.

Note: In the DOM4 specification (as implemented in Gecko 13.0 (Firefox 13 / Thunderbird 13 / SeaMonkey 2.10)), deep is an optional argument. If omitted, the method acts as if the value of deep was true, defaulting to using deep cloning as the default behavior. To create a shallow clone, deep must be set to false.

This behavior has been changed in the latest spec, and if omitted, the method will act as if the value of deep was false. Though It's still optional, you should always provide the deep argument both for backward and forward compatibility. With Gecko 28.0 (Firefox 28 / Thunderbird 28 / SeaMonkey 2.25 / Firefox OS 1.3), the console warned developers not to omit the argument. Starting with Gecko 29.0 (Firefox 29 / Thunderbird 29 / SeaMonkey 2.26)), a shallow clone is defaulted instead of a deep clone.


var iframe = document.getElementsByTagName("iframe")[0];
var oldNode = iframe.contentWindow.document.getElementById("myNode");
var newNode = document.importNode(oldNode, true);


O nó original não é removido do documento de origem. O nó importado é um clone do original.


Nodes from external documents should be cloned using document.importNode() (or adopted using document.adoptNode()) before they can be inserted into the current document. For more on the Node.ownerDocument issues, see the W3C DOM FAQ.

Firefox doesn't currently enforce this rule (it did for a while during the development of Firefox 3, but too many sites break when this rule is enforced). We encourage Web developers to fix their code to follow this rule for improved future compatibility.



Specification Status Comment
The definition of 'document.importNode()' in that specification.
Padrão em tempo real  
Document Object Model (DOM) Level 2 Core Specification
The definition of 'document.importNode()' in that specification.
Obsoleto Initial definition

Compatibilidade nos Browsers

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
importNodeChrome Full support 1Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 9Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support YesSamsung Internet Android ?
deep parameter optionalChrome Full support YesEdge Full support YesFirefox Full support 10IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 10Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?


Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

Veja também