Reputation: 59252
I have two functions.
function foo(elems){
elems.each(function(){
});
}
foo($('selector1,selector2')); // calling foo
function bar(elem1,elem2){
// some logic
}
bar($('selector1'),$('selector2)); // calling bar
However, now I need to use foo()
inside bar()
.
function bar(elem1,elem2){
foo(?); // I'm stuck here. I want to pass both elem1 and elem2 as single jquery object
}
So I tried $(elem1,elem2)
but it only includes elem1
. So what should I do, so that I can pass elem1
and elem2
as a single jquery object which I'll iterate over in foo()
by .each()
Upvotes: 3
Views: 66
Reputation: 2219
You can use the jQuery "add" method, like this
$(elem1).add(elem2); //this now contains both elements
Upvotes: 1
Reputation: 78545
You can use .add:
foo(elem1.add(elem2));
To combine the results of both selectors
Upvotes: 2