admin管理员组文章数量:1335593
I want to select all items which are in one class and NOT in a set of other classes. For the first step, I imagined something like this would work, but didn't:
$('.class1,!.class2')
What I actually have is a list of classes that I don't want to select:
dont_select = ['class2', 'class3', 'class4']
And I want to select all items which have class1 but not any class in my array of classes in dont_select (which varies in length). Thanks,
I want to select all items which are in one class and NOT in a set of other classes. For the first step, I imagined something like this would work, but didn't:
$('.class1,!.class2')
What I actually have is a list of classes that I don't want to select:
dont_select = ['class2', 'class3', 'class4']
And I want to select all items which have class1 but not any class in my array of classes in dont_select (which varies in length). Thanks,
Share Improve this question asked Nov 16, 2012 at 19:17 mikemike 23.8k32 gold badges81 silver badges100 bronze badges4 Answers
Reset to default 6Try this:
$(".class1").not("." + dont_select.join(",.") );
Give this a shot:
$(".class1:not(.class2)")
$(".class1:not(" + dont_select.join() + ")");
You should use .not
function. See below,
dont_select = ['.class2', '.class3', '.class4']
$(selector).not(dont_select.join())
Note: Added a . to the string in dont_select array
Your simple selector will be as below with Jquery
$('div.class1').not('.class2,.class3');
in the .not function of jquery you can put as much element as you want after ","
or if you have array then you can also go with the suggestion of Vega
dont_select = ['.class2', '.class3', '.class4']
$(selector).not(dont_select.join())
Go Ahead !!!
本文标签: Select items with one class and not other class jquery javascriptStack Overflow
版权声明:本文标题:Select items with one class and not other class jquery javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742375995a2463175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论