When having called .before
on elements that are detached from the DOM, .end
behaves differently than it does with attached elements:
var $div1 = $("div");
console.log($div1.after("foo").end()); // [document]
$div1.detach();
console.log($div1.after("foo").end()); // [<div></div>]
(Fiddle: http://jsfiddle.net/R2uc7/2/)
Apparently, .before
causes different behaviour to .end
depending on the node being attached or detached. I don't see the logic and I'm not sure what I can rely on.
Could someone enlighten me on the defined behaviour of .end
combined with .before
?