What is the opposite of jQuerys “hasClass”?

0 votes
asked Nov 3, 2010 by luke-the-obscure

Currently I have some code that reads

    if ( $(this).hasClass('.someclass') ) 
     { } 
     else {
     //Do Stuff here.
     }

I know this isn't exactly kosher, but it works.

What's the proper way to go about this? How do I check for the abscence of a class?

1 Answer

0 votes
answered Nov 3, 2010 by mark-byers

Invert the test:

if (!$(this).hasClass('someclass')) 

I think also that the . should not be in front of the class name. See the documentation.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...