Omid Omid - 2 days ago 4
jQuery Question

JQuery on multple objects

if we have something like this:

var foo=$('.foo');
var boo=$('.boo');
var koo=$('.koo');


Then is there any possibility to put
foo
,
boo
and
koo
in one
JQuery
object with
$
function ?

I Tried these:

$(foo,koo,boo).removeClass('someClass'); // nothing happened
$([foo,koo,boo]).removeClass('someClass'); // nothing happened


But nothing happend.

PS. I know I can use direct selector with
$('.foo,.boo,.koo')
but this is not what I'm looking for

Answer

If you already have several jQuery objects, you can use $.add():

var combo = foo.add(koo).add(boo)
combo.removeClass('someClass')
Comments