在jQuery中,如何在没有给定类的情况下选择所有元素? [英] How can I select all elements without a given class in jQuery?
本文介绍了在jQuery中,如何在没有给定类的情况下选择所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出以下内容:
<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>
如何选择除项目2以外的所有内容,又称类似的东西:
How can I select all but Item 2, AKA something like:
$("ul#list li!active")
推荐答案
You can use the .not()
method or :not()
selector
基于您的示例的代码:
$("ul#list li").not(".active") // not method
$("ul#list li:not(.active)") // not selector
这篇关于在jQuery中,如何在没有给定类的情况下选择所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文