How to check if an element does NOT have a specific class?

user1005793 picture user1005793 · Oct 20, 2011 · Viewed 369.6k times · Source

How do I check if there isn't a class. For example, I know how to check to see if it has the class "test", but how do I check to see if it doesn't have the class "test"?

if($(this).hasClass("test")){
}

Answer

sdleihssirhc picture sdleihssirhc · Oct 20, 2011
if (!$(this).hasClass("test")) {