In this article a detached Div node is created:
http://www.bennadel.com/blog/1008-jQuery-empty-Kills-Event-Binding-On-Persistent-Nodes.htm
I don’t understand : I thought that DOM owns every nodes. How would you attach to DOM then ?
Last but not least what would be the purpose of having detached node ?
I’m not sure which answer you expect, so here are some thoughts:
The document owns every node. Each node has an
ownerDocument[MDN] property.From the specification:
There are various ways to insert a new node, such as
appendChild[docs] orinsertBefore[docs].One advantage is that you can build complex subtrees offline so that the browser does not have to recalculate the layout every time you insert a node.
Sometimes it is also useful for parsing an HTML string. By creating an empty, detached
divand assign the HTML string toinnerHTML, you can parse and process the HTML string easily.The only caveat is that
document.getElementByIdcannot find nodes which are not part of the tree.Also interesting in this regard might be the explanation for the
Node.parentNodeproperty. After all, aNodewhich does not have parent is not part of the tree: