Valentin V
Valentin V

Reputation: 25799

How to find all elements that DON'T have specific CSS class in jQuery?

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.

Upvotes: 4

Views: 1825

Answers (3)

karim79
karim79

Reputation: 342795

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

Upvotes: 8

Russ Cam
Russ Cam

Reputation: 125538

$("input:not(.bad)")

Upvotes: 5

kgiannakakis
kgiannakakis

Reputation: 104196

You can use the not() filter:

$("input").not(".bad")

Upvotes: 17

Related Questions