Is there an .add() that adds to the existing jQuery object?
I'm writing some code that responds to a set of filters. The way I'm trying to tackle it is first determine which elements should be hidden and which elements should be shown, and then hide or show those elements. That way the elements are all hidden or shown more instantaneously without having to evaluate criteria in between each one. After I identify an element that should be shown, I need to store it in a group of elements to be shown. I was thinking of doing something like this:
- var $elementsToShow = $();
-
containers.each(function(){
- if([criteria])
- $elementsToShow = $elementsToShow.add($(this));
- });
-
$elementsToShow.toggle(true);
What I'm worried about is that add creates a new jQuery instance each time. That's a lot of extra work for garbage collection. Is there a way to add the element to an existing jQuery?