jqueryradio-buttonchecked

how to get checked radio button with jQuery after changing the default checked="checked"


I have a group of radio buttons with one of them checked by default:

<input type='radio' name='myradios' value='flat'>
<input type='radio' name='myradios' value='ball' checked='checked'>
<input type='radio' name='myradios' value='list'>

How can I get the checked value after they have been changed (another one was clicked)

I tried jQuery("input[name=myradios]:checked").val(), but unfortunately jQuery("input[name=myradios]:checked") gives a list that ALWAYS includes the one that originally had the checked="checked" property, so depending on "luck" (order of the buttons, whether the one I clicked is before or after the one that was the default) I do get good or wrong value.


Solution

  • $('input[name="myradios"]').change(function() {
       alert($(this).val());
    });