Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document.importNode VS Node.cloneNode (real example)

Document.importNode in specification

Node.cloneNode in specification

This two methods work equally. Please give me real example in which I can see the difference between this methods.

like image 697
Iaroslav Baranov Avatar asked Sep 07 '16 14:09

Iaroslav Baranov


1 Answers

Alohci is right: there's not much of a difference, since web compatibility forced the browsers to implicitly adoptNode() before inserting a node into another document.

Before you insert the cloned node into a new document, there's a difference: the owner document of the node returned by the cloneNode(original) is the same as of the original node, and the new document if you call newDocument.importNode(original). You can see this difference if you use ownerDocument or related properties (such as baseURI).

But if you call importNode on the same document that the original node belongs to, there's no difference whatsoever.

like image 171
Nickolay Avatar answered Oct 20 '22 21:10

Nickolay