Ricky
Ricky

Reputation: 35863

how to use is()

How to refactor the follow to put NOT is(":checked") syntax, instead put the codes being executed in the else block?

if ($(this).is(":checked")) {
    // do nothing
}
else {
    // To do here
}

Thanks for all the help.

Upvotes: 1

Views: 81

Answers (2)

Roman
Roman

Reputation: 20246

Do you want this, or am I missing something?

if( $(this).is(":checked") == false) 
{
    // To do here
}

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630459

You would add a negation (!) to it, like this:

if (!$(this).is(":checked")) {

But you can just use the checked DOM property directly here, which is much faster:

if (!this.checked) {

Upvotes: 6

Related Questions