最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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.

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.

Share Improve this question asked Jul 22, 2009 at 11:54 Valentin VValentin V 25.7k34 gold badges109 silver badges154 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 17

You can use the not() filter:

$("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)")
发布评论

评论列表(0)

  1. 暂无评论