不是jQuery中的类选择器 [英] Not class selector in jQuery
本文介绍了不是jQuery中的类选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一个简单的选择器表达式不能选择具有特定类的元素?
Is there a simple selector expression to not select elements with a specific class?
<div class="first-foo" />
<div class="first-moo" />
<div class="first-koo" />
<div class="first-bar second-foo" />
我只想获得前三个div并尝试
I just want to get the first three divs and tried
$(div[class^="first-"][class!="first-bar"])
但是这会收到所有,因为最后一个div包含的不仅仅是第一个栏。有没有办法在这样的表达式中使用占位符?类似的东西
But this receives all as the last div contains more than first-bar. Is there a way to use a placeholder in such an expression? Something like that
$(div[class^="first-"][class!="first-bar*"]) // doesn't seem to work
任何其他可能有帮助的选择器?
Any other selectors that may help?
推荐答案
您需要 :not()
selector:
You need the :not()
selector:
$('div[class^="first-"]:not(.first-bar)')
或者,或者, .not()
方法:
or, alternatively, the .not()
method:
$('div[class^="first-"]').not('.first-bar');
这篇关于不是jQuery中的类选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文