Find out whether radio button is checked with JQuery? Find out whether radio button is checked with JQuery? jquery jquery

Find out whether radio button is checked with JQuery?


$('#element').click(function() {   if($('#radio_button').is(':checked')) { alert("it's checked"); }});


If you have a group of radio buttons sharing the same name attribute and upon submit or some event you want to check if one of these radio buttons was checked, you can do this simply by the following code :

$(document).ready(function(){  $('#submit_button').click(function() {    if (!$("input[name='name']:checked").val()) {       alert('Nothing is checked!');        return false;    }    else {      alert('One of the radio buttons is checked!');    }  });});

Source

jQuery API Ref


As Parag's solution threw an error for me, here's my solution (combining David Hedlund's and Parag's):

if (!$("input[name='name']").is(':checked')) {   alert('Nothing is checked!');}else {   alert('One of the radio buttons is checked!');}

This worked fine for me!