admin管理员组文章数量:1128487
Is there a simple selector expression to not select elements with a specific class?
<div class="first-foo" />
<div class="first-moo" />
<div class="first-koo" />
<div class="first-bar second-foo" />
I just want to get the first three divs and tried
$(div[class^="first-"][class!="first-bar"])
But this receives all as the last div contains more than first-bar. Is there a way to use a placeholder in such an expression? Something like that
$(div[class^="first-"][class!="first-bar*"]) // doesn't seem to work
Any other selectors that may help?
Is there a simple selector expression to not select elements with a specific class?
<div class="first-foo" />
<div class="first-moo" />
<div class="first-koo" />
<div class="first-bar second-foo" />
I just want to get the first three divs and tried
$(div[class^="first-"][class!="first-bar"])
But this receives all as the last div contains more than first-bar. Is there a way to use a placeholder in such an expression? Something like that
$(div[class^="first-"][class!="first-bar*"]) // doesn't seem to work
Any other selectors that may help?
Share Improve this question asked Jan 6, 2011 at 10:51 medihackmedihack 16.6k21 gold badges91 silver badges140 bronze badges 2 |4 Answers
Reset to default 675You need the :not()
selector:
$('div[class^="first-"]:not(.first-bar)')
or, alternatively, the .not()
method:
$('div[class^="first-"]').not('.first-bar');
You can use the :not
filter selector:
$('foo:not(".someClass")')
Or not()
method:
$('foo').not(".someClass")
More Info:
- http://api.jquery.com/not-selector/
- http://api.jquery.com/not/
You can write a jQuery selector in the "not" method:
$('div[class^="first-"]').not($('.first-bar'))
It also works on jQuery events with :not()
selector.
Simply like this :
jQuery(document).on('click', '.fo-line:not(.deleted) .clickable', function(e) {
e.preventDefault();
// do your stuff...
});
In my case, I enable click on every <td class="clickable">
of <tr class="fo-line">
expected all with deleted
class (<tr class="fo-line deleted">
)
本文标签: javascriptNot class selector in jQueryStack Overflow
版权声明:本文标题:javascript - Not class selector in jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736724861a1949671.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
first-bar
. – BoltClock Commented Jan 6, 2011 at 10:54$('div[class^="first-"]').not('.class1').not('.class2')
– J0ANMM Commented Nov 15, 2017 at 12:06