views:

6468

answers:

2

I've had a good look and can't seem to find how to select all elements matching certain classes in one jQuery selector statement such as this:

$('.myClass', '.myOtherClass').removeClass('theclass');

Any ideas on how to achieve this? The only other option is to do

$('.myClass').removeClass('theclass');
$('.myOtherClass').removeClass('theclass');

But I'm doing it against quite a few so it requires much code.

+32  A: 

This should work:

$('.myClass, .myOtherClass').removeClass('theclass');

You must add the multiple selectors all in the first argument to $(), otherwise you are giving jQuery a context in which to search, which is not what you want.

It's the same as you would do in CSS.

eamelink
That was a quick answer, thanks very much!
Kezzer
+10  A: 

Have you tried this?

$('.myClass, .myOtherClass').removeClass('theclass');
Ionuț G. Stan