Alex Rivera | Logout

Get the currently selected radio button in a jquery ui buttonset without binding to click

Asked 2012-01-18T10:58:56.510
23

I have radio buttons like this:

<div id="radio">
    <input type="radio" id="radio1" name="radioOption" /><label for="radio1">Choice 1</label>
    <input type="radio" id="radio2" name="radioOption" checked="checked" /><label for="radio2">Choice 2</label>
    <input type="radio" id="radio3" name="radioOption" /><label for="radio3">Choice 3</label>
</div>

And apply the button set like this:

$(function () {
    $("#radio").buttonset();
});

I need to get the selected radio button without binding to the click event.

Edit
Report

1 Answer

61

Damn just realised my selecter had a typo, but if it helps anyone else:

If you dont want to use the click event, which I didn't you could do the following: If you're looking for the element it self use:

$("#radio :radio:checked");

If you're looking for the id of the element use:

$("#radio :radio:checked").attr('id');

If you're need to know what the text of the value selected then this should work:

$("#radio :radio:checked + label").text();
answered 2012-01-18T11:01:21.813

Your Answer