views:

106

answers:

3

I would like to get all form elements that don't 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>

What selector should I use to select all elements that don't have 'bad' css class?

Thank you.

+10  A: 

You can use the not() filter:

$("input").not(".bad")
kgiannakakis
hmm.. not bad !
I.devries
+5  A: 

You can also use the not selector:

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

Note the quotes are not needed:

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

See:

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

karim79
The quotes around .bad in the :not selector aren't needed
Russ Cam
@Russ Cam - true, added that to the answer.
karim79
+4  A: 
$("input:not(.bad)")
Russ Cam