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

JavascriptJqueryCssJquery Selectors

Javascript Problem Overview


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

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

...

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

Javascript Solutions


Solution 1 - Javascript

Use :not() to exclude the other class:

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

Solution 2 - Javascript

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

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

Solution 3 - Javascript

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();

Solution 4 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - JavascriptBoltClockView Answer on Stackoverflow
Solution 2 - JavascriptJoey C.View Answer on Stackoverflow
Solution 3 - JavascriptDavid BotskoView Answer on Stackoverflow
Solution 4 - JavascriptSouravView Answer on Stackoverflow