jquery-radio
makes it easy to get or set the current value of a group of radio buttons, filling a gap in jQuery's $.val()
.
Select all of the buttons in the group and call .radio()
:
// Check the box with value="5"
$('input.my-radio-group').radio(5);
// Get the value of the checked box
var value = $('input.my-radio-group').radio();
This example assumes you have several radio buttons that all have the .my-radio-group
class.
You need jQuery, of course. jquery-radio
is actively supported with jQuery 1.9 and 2.0 but should work fine with older versions.
0.1.3: cross browser support for IE and Firefox, which don't like the use of jQuery's attr
to manipulate checkboxes very much. What does work is a combination of setAttribute
and the checked
property on the DOM element itself.
jquery-radio
was created at P'unk Avenue for use in Apostrophe, an open-source content management system built on node.js. If you like jquery-radio
you should definitely check out apostrophenow.org. Also be sure to visit us on github.
Feel free to open issues on github.