tags:

views:

46

answers:

2
+1  Q: 

how to use is()

Hi guys,

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.

+6  A: 

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) {
Nick Craver
`!this.checked` is probably better, no point round-tripping it through jQuery just to get a value that's already available through the DOM element.
R0MANARMY
+1  A: 

Do you want this, or am I missing something?

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