如何在 jQuery 中选择没有给定类的所有元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2448051/
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
How can I select all elements without a given class in jQuery?
提问by Andrew G. Johnson
Given the following:
鉴于以下情况:
<ul id="list">
<li>Item 1</li>
<li class="active">Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
</ul>
How can I select all but Item 2, AKA something like:
我怎样才能选择除第 2 项之外的所有内容,也就是:
$("ul#list li!active")
回答by Andre Backlund
回答by Andy Shellam
What about $("ul#list li:not(.active)")
?
怎么样$("ul#list li:not(.active)")
?
回答by Oswaldo Ferreira
You could use this to pick all li
elements without class:
您可以使用它来选择li
没有类的所有元素:
$('ul#list li:not([class])')
回答by George Sisco
Refer to the jQuery API documentation: not() selectorand not equal selector.
请参阅 jQuery API 文档: not() selector和not equal selector。
回答by user3763117
if (!$(row).hasClass("changed")) {
// do your stuff
}