I am trying to manually set a radio button to checked, but there is a problem. The code works just fine:
$('#'+align+'Text').attr("checked","checked");
But when I put jQuery UI into practice and make the radios a buttonset, everything breaks. Again, everything works fine until I put in the .buttonset(), then they look much better than normal radios, but the setting above does not work at all.
EMPHASIS ON THE FOLLOWING:
Has anyone been able to manually set a radio button while .buttonset() is active on those radios?
I am trying to manually set a radio button to checked, but there is a problem. The code works just fine:
$('#'+align+'Text').attr("checked","checked");
But when I put jQuery UI into practice and make the radios a buttonset, everything breaks. Again, everything works fine until I put in the .buttonset(), then they look much better than normal radios, but the setting above does not work at all.
EMPHASIS ON THE FOLLOWING:
Has anyone been able to manually set a radio button while .buttonset() is active on those radios?
1 Answer
Reset to default 23All you need to do is call the "refresh" operation on the button widget after setting the "checked" attribute.
$('#'+align+'Text').attr("checked","checked").button('refresh');
Here's the jsfiddle.
Note that setting the "checked" property can (and, some would say, should) be set with the .prop()
function:
$('#' + align + 'Text').prop('checked', true).button('refresh');
checked
property is a Boolean value, it's set by being either present or not-present. It doesn't require an attribute. Try using:attr('checked',true)
instead. It might make a difference. – David Thomas Commented Feb 28, 2011 at 18:05