how to retrieve value of radio button sets by class

I have a series of radio buttons with class="weight"
I thought I could get the current selected value with this:

$('.weight radio:checked').val()

...but does not seem to work. I also have them with a name="weight" so if its easier to do this by name, that would be an OK solution as well.

Thank you!
Brad BansnerWeb DeveloperAsked:
Who is Participating?
 
Gurvinder Pal SinghConnect With a Mentor Commented:
it should be

$('input[type='radio'].weight:checked').val()

or just

$('.weight:checked').val()
0
 
Gurvinder Pal SinghCommented:
to fetch by name


$('input[name='weight']:checked').val()
0
 
Brad BansnerWeb DeveloperAuthor Commented:
Excellent, thanks.
0
 
leakim971PluritechnicianCommented:
just add << : >> and no space before radio : $(".weight:radio:checked").val()
test page : http://jsfiddle.net/dahVc/

$(".weight:radio").change(function() {
    //alert( $(this).val() );
    alert( $(".weight:radio:checked").val() );
})

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.