I am reading the book jQuery in Action - Bibeault, Katz, based on jQuery 1.2 on the paragraph about remove() command.
It’s clear that this command removes all elements in the wrapped set from the page DOM, but I don’t understand what returns, (and it seems that on the remove() command page on the jquery website there aren’t any additional explanations about it). On the book, I am arrived to read the following, but I don’t understand its meaning:
as with many other jQuery commands, the wrapped set is returned as the result of this command. The elements that were removed from the DOM are still referenced by this set (and hence not yet eligible for garbage collection) and can be further operated upon using other jQuery commands including appendTo(), prependTo(), insertBefore(), insertAfter() and any other similar behaviours we’d like.
does it mean that the removed element is still available? and in what way? Why on the site, there isn’t any of what I cited? Can you give me any clarifications with examples? Many thanks!
[quote=“franciska, post:1, topic:229987, full:true”]
On the book, I am arrived to read the following, but I don’t understand its meaning:
as with many other jQuery commands, the wrapped set is returned as the result of this command. The elements that were removed from the DOM are still referenced by this set (and hence not yet eligible for garbage collection) and can be further operated upon using other jQuery commands including appendTo(), prependTo(), insertBefore(), insertAfter() and any other similar behaviours we’d like.
does it mean that the removed element is still available?[/quote]
Yes it does.
[quote=“franciska, post:1, topic:229987, full:true”]
and in what way?[/quote]
The selected elements are added to an internal stack, which gets returned as a jQuery object allowing you to chain further actions on to them.
Chapter two takes you through some of those details of the wrapped set.
I thought that there was. You might just not have thought to chase it down.
Go to the .remove() documentation page and you’ll see to the right of .remove( [selector ] ) that it says “Returns: jQuery”
Following that link takes you to a page that says things like:
Whenever you use a "destructive" jQuery method that potentially changes the set of elements in the jQuery object, such as .filter() or .find(), that method actually returns a new jQuery object with the resulting elements.
Garbage collection means that objects which are not reachable (either because there’s no reference any more or because the only reference is some sort of cycle) are getting deleted automatically, so that the memory gets freed. So jQuery objects which are getting removed are not getting garbage collected as long as they still have a reachable reference.