Javascript 不是 jQuery 中的类选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4614120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Not class selector in jQuery
提问by Zardoz
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" />
I just want to get the first three divs and tried
我只想获得前三个 div 并尝试
$(div[class^="first-"][class!="first-bar"])
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 包含的不仅仅是第一个栏。有没有办法在这样的表达式中使用占位符?类似的东西
$(div[class^="first-"][class!="first-bar*"]) // doesn't seem to work
Any other selectors that may help?
任何其他可能有帮助的选择器?
回答by lonesomeday
回答by Sarfraz
You can use the :not
filter selector:
您可以使用:not
过滤器选择器:
$('foo:not(".someClass")')
Or not()
method:
或not()
方法:
$('foo').not(".someClass")
More Info:
更多信息: