Radio buttons not marked in jQuery

I have this line of code to load the page:

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

and it works fine when the switch is set. However, I want the opposite. Something along the lines

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

so the my if statement runs when none of the radio blocks are selected. What is the best way to do this?

+47
jquery
Dec 16 '08 at 19:08
source share
7 answers
 if ( ! $("input").is(':checked') ) 

Does not work?

You can also try iterating over the following elements:

 var iz_checked = true; $('input').each(function(){ iz_checked = iz_checked && $(this).is(':checked'); }); if ( ! iz_checked ) 
+59
Dec 16 '08 at 19:22
source share
 if ($("input").is(":not(:checked)")) 

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

+20
Dec 17 '08 at 8:08
source share

If my firebug profiler is working fine (and I know how to use it), this is:

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

faster than

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

You can try this page :)

And then you can use it as

 if($('#communitymode').attr('checked')===true) { // do something } 
+9
Dec 17 '08 at 9:16
source share
 $("input").is(":not(':checked')")) 

This is jquery 1.3, pay attention to the signs and!

+8
Oct 28 '09 at 2:30 p.m.
source share
 $('input:radio[checked=false]'); 

it will also work

 input:radio:not(:checked) 

or

 :radio:not(:checked) 
+5
May 14 '10 at 19:44
source share

check this

 if($("#selector").is(":checked")) { alert('Checked'); } else { alert('Not checked'); } 

You can specify id or class, for example, in the place of the selector

+4
Mar 07 2018-12-12T00:
source share

This also works. Shortest working notation seems to be:! !$('#selector:checked')

0
Dec 25 '17 at 7:27
source share



All Articles