开发者

How can I select all elements without a given class in jQuery?

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:

$("ul#list li!active")


You can use the .not() method or :not() selector

Code based on your example:

$("ul#list li").not(".active") // not method
$("ul#list li:not(.active)")   // not selector


What about $("ul#list li:not(.active)")?

http://api.jquery.com/not-selector/


You could use this to pick all li elements without class:

$('ul#list li:not([class])')


Refer to the jQuery API documentation: not() selector and not equal selector.


if (!$(row).hasClass("changed")) {
    // do your stuff
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜