How can I determine if my radio buttons are selected?
For example:
if ( radio_button_selected ) { // do something } else { // do something else } How can I determine if my radio buttons are selected?
For example:
if ( radio_button_selected ) { // do something } else { // do something else } You can use this selector to determine if any are checked:
jQuery("input[name='my_button_group']:checked") So for example:
if (jQuery("input[name='my_button_group']:checked")) { ... } else { ... } input).If you have your radio button rb already selected through other means, you can do:
var rb = $('whatever selector'); // other code if (rb.is(':checked')) { // code } rb.checked is a better choice - it's faster and more readable.checked is not a property of a jquery list object. The actual DOM object has the checked property.rb[0].checked is the correct solution (and it is still faster).If you have a reference to the element already, you can use its checked property:
$('input[type=radio]').focus(function(){ // "this" is the element that was clicked if (this.checked) { // do something } else { // do something else } }); focus to illustrate my point.if ($("input[name='yourRadioName']:radio:checked").length) { } else { } :radio ensures that a radio button is selected and not just any checked input with the name "yourRadioName".. However you are right using input would execute faster.