The main jQuery method takes a second optional argument to provide context for the search. eg
$('.setA', ancestorOfSetsA);
However, the jQuery add() method does not accept this context argument. What I am trying to accomplish is:
$('.setA', ancestorOfSetsA).add('.setB', ancestorOfSetsB);
I am attempting this through a plugin that will overload the add() method but I can’t figure out how to combine two jQuery objects into one jQuery object.
I would like to find a way to do a scoped add() with jQuery, but failing that, I’ll write one myself if I can find a way to merge to jQuery objects.
You can pass a jQuery collection into
addjust as well as a selector string:If you want to overload
addthen you’ll need to be careful to support the all of its behaviour. Someone (a plugin you might be using) might do this:Updated:
Here is the current add function from jQuery modified to take a context parameter: