How to find all elements that do not have a specific CSS class in jQuery?

I would like to get all form elements that do not have a specific CSS class. Example:

<form> <div> <input type="text" class="good"/> <input type="text" class="good"/> <input type="text" class="bad"/> </div> </form> 

Which selector should be used to select all elements that do not have a "bad" css class?

Thanks.

+4
source share
3 answers

You can use the not () filter:

 $("input").not(".bad") 
+16
source

You can also use not selector :

 $('input:not(".bad")').hide(); 

Note that quotation marks are not needed:

 $('input:not(.bad)').hide(); 

Cm:

http://docs.jquery.com/Selectors/not

+8
source
 $("input:not(.bad)") 
+5
source

All Articles