I noticed in some code samples to seemingly different ways to clone a DOM node and append it to an existing element:
element.appendChild(something.cloneNode(true));
element.appendChild(document.importNode(something, true));
Both have the effect of copying a node. The second version seems more verbose, and implies that the copy is actually somewhere concrete first, though it still needs to find a proper home. However, it is used by MDN and a few other as an illustration of using the template
tag. Elsewhere they go for the simpler clodeNode
option.
The question is: what is the benefit to using importNode
over cloneNode
?