clone(true) + remove() vs. detach() in jQuery

detach, jquery

Solution

Same same but different: If you just clone a node without assigning it to a variable you will lose the copied node's reference and therefore any chance to gain a hand on its event handlers and other data (not quite true but its a PITA).

EDIT Yes, holding a reference to the cloned element you have an exact copy (mind the true param though) that can later be appended to the DOM.

Problem

Is the usage of ``` e = elem.clone(true); elem.remove(); ``` Identical to ``` e = elem.detach(); ``` If later I append it with ``` e.appendTo($("#someDiv")); ``` In jQuery 1.4? Will the clone(true) method preserve everything using detach() does?

Original source