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?
We can check the status of a radio button by using the :checked jQuery selector together with the jQuery function is . For example: $('#el').is(':checked') . It is exactly the same method we use to check when a checkbox is checked using jQuery.
Using Input Radio checked property: The Input Radio checked property is used to return the checked status of an Input Radio Button. Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.
if ( ! $("input").is(':checked') )
Doesn't work?
You might also try iterating over the elements like so:
var iz_checked = true; $('input').each(function(){ iz_checked = iz_checked && $(this).is(':checked'); }); if ( ! iz_checked )
if ($("input").is(":not(:checked)"))
AFAIK, this should work, tested against the latest stable jQuery (1.2.6).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With