Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

People also ask

How do you select an element without a class?

In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.

Can you select multiple elements in jQuery?

In jQuery, you can select multiple elements by separate it with a comma “,” symbol. In above case, select all elements that have a class name of “class1” and “class2”, and id of “id1”.


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
}