Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

javascript - 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.

question from:https://stackoverflow.com/questions/39372886/document-importnode-vs-node-clonenode-real-example

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...