If I have a list like this:
<ul>
<li class="A"></li>
<li class="A B"></li>
<li class="A C"></li>
</ul>
Using jQuery, how would I select only the first item, but not the other two? In other words, how do I write a selector that will only select an element that does not have class B or C?
$('li.A:not(.B,.C)')
$(function() {
$(".a").not('.b, .c').text('aaa');
});
jsfiddle: http://jsfiddle.net/bitsmix/h2fpq/
You can either use the :not()
selector or .not()
method:
$('.a').not('.b, .c')
$('.a:not(.b,.c)')
您可以使用.not()方法:
$('li.a').not('.b, .c')
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.