Andrew G. Johnson Andrew G. Johnson - 1 year ago 65
jQuery Question

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>

How can I select all but Item 2, AKA something like:

$("ul#list li!active")

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download