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.
To get the value of selected radio button, a user-defined function can be created that gets all the radio buttons with the name attribute and finds the radio button selected using the checked property. The checked property returns True if the radio button is selected and False otherwise.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With