Jim G.
Jim G.

Reputation: 15365

jQuery: How can you test for the *absence* of a class?

Given that this is the correct way to see if 'this' has class 'selected':

if ($(this).hasClass('selected')) {
   // logic goes here
}

What is the correct way to test for the absence of a class?

That is, how can I test if 'this' does not have class 'selected'?

Upvotes: 1

Views: 1076

Answers (1)

Venr
Venr

Reputation: 937

if (!$(this).hasClass('selected')) {
    // logic goes here
}

Upvotes: 7

Related Questions