简体   繁体   中英

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.

您可以使用not()过滤器:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM