Dave Dave - 11 months ago 54
Javascript Question

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

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>

And apply the button set like this:

$(function () {

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


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();