开发者

jQuery select a div with a certain class, that doesn't have another class

开发者 https://www.devze.com 2023-02-22 15:44 出处:网络
<div class=\"fuu\"> ... &l开发者_运维知识库t;/div> <div class=\"fuu no\"> ... </div>
<div class="fuu">
  ...
&l开发者_运维知识库t;/div>

<div class="fuu no">
  ...
</div>

...

How can I select all fuu's besides the ones that have the .no class?


Use :not() to exclude the other class:

$('.fuu:not(.no)')


You can also filter out the '.no' class with something like:

$('.fuu').not('.no');


I couldn't get the first answer to work until I added another set of quotes. This gave me the desired result of selecting the class that excluded a second class.

$(".fuu:not('.no')").hide();


get the div's class name, if it has a SPACE in the class name then it means it has more than one class !

0

精彩评论

暂无评论...
验证码 换一张
取 消