[jquery] Radio buttons not checked in jQuery

I have this line of code for page load:

if ($("input").is(':checked')) {

and it works fine when the radio button input is checked. However, I want the opposite. Something along the lines of

if ($("input").not(.is(':checked'))) {

so that my if statement runs when none of the radiobuttons are selected. What is the best way to go about this?

This question is related to jquery

The answer is


If my firebug profiler work fine (and i know how to use it well), this:

$('#communitymode').attr('checked')

is faster than

$('#communitymode').is('checked')

You can try on this page :)

And then you can use it like

if($('#communitymode').attr('checked')===true) { 
// do something
}

if ($("input").is(":not(:checked)"))

AFAIK, this should work, tested against the latest stable jQuery (1.2.6).


This works too. It seems shortest working notation: !$('#selector:checked')


if ($("input").is(":not(:checked)"))

AFAIK, this should work, tested against the latest stable jQuery (1.2.6).


$("input").is(":not(':checked')"))

This is jquery 1.3, mind the ' and " signs!


$('input:radio[checked=false]');

this will also work

input:radio:not(:checked)

or

:radio:not(:checked)

(!$('#radio').is(':checked'))

This worked for me


If my firebug profiler work fine (and i know how to use it well), this:

$('#communitymode').attr('checked')

is faster than

$('#communitymode').is('checked')

You can try on this page :)

And then you can use it like

if($('#communitymode').attr('checked')===true) { 
// do something
}

$("input").is(":not(':checked')"))

This is jquery 1.3, mind the ' and " signs!


This works too. It seems shortest working notation: !$('#selector:checked')


(!$('#radio').is(':checked'))

This worked for me


If my firebug profiler work fine (and i know how to use it well), this:

$('#communitymode').attr('checked')

is faster than

$('#communitymode').is('checked')

You can try on this page :)

And then you can use it like

if($('#communitymode').attr('checked')===true) { 
// do something
}

If my firebug profiler work fine (and i know how to use it well), this:

$('#communitymode').attr('checked')

is faster than

$('#communitymode').is('checked')

You can try on this page :)

And then you can use it like

if($('#communitymode').attr('checked')===true) { 
// do something
}

$('input:radio[checked=false]');

this will also work

input:radio:not(:checked)

or

:radio:not(:checked)