Cecil Theodore
Cecil Theodore

Reputation: 9939

IF statement when check box is NOT selected JQUERY

I have an if statement where I want to say IF a check box is NOT checked and the div has a class of checkBoxID, run the function.

The problem I have is how to use the :not selector with this

$(this:not(:checked)) does not work. I would like to know if there is a way to use the :not selector in the same manor as you would when running a function when a check box IS selected.

Here is my current function below.

if ($(this).is(':checked') && $('div').hasClass(checkBoxID))
            {
                // do something..
            }

So just to clarify, this current function works when the check box is checked, I want it to work in the opposite direction when the check box is NOT clicked.

Thank you!

Upvotes: 0

Views: 489

Answers (3)

Travis J
Travis J

Reputation: 82287

Sorry to re-iterate, AndreasAL answered this as well.

$(this:not(:checked))

will not work because the syntax is wrong, it should be

$(this.not(:checked))

Upvotes: 0

Andreas Louv
Andreas Louv

Reputation: 47099

use is like .is

$(this).not(":checked")

Upvotes: 1

lkurylo
lkurylo

Reputation: 1641

if(!$(this).is(':checked'))
{
//..
}

Upvotes: 3

Related Questions