.remove()
removes the jQuery internal data about the contained elements from jQuery.cache
. Such data includes custom data set with .data()
and the data required by jQuery's event model.
.detach()
does not remove that data.
.remove()/.detach()
additionally just remove the element(s) from the DOM tree. It's like removing an item from an array... the item itself does not just magically vanish even if it's no longer in the array. Especially if you keep a reference to it like you are doing in your code.