Selecting multiple classes with jQuery

I've had a good look and can't seem to find out 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 this with quite a few classes, so it requires much code.


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.


你试过这个吗?

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

我使用$('.myClass.myOtherClass').removeClass('theclass');

链接地址: http://www.djcxy.com/p/83110.html

上一篇: 使用jQuery获取所选选项的文本

下一篇: 用jQuery选择多个类