Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery manually set buttonset 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?

like image 503
Yottagray Avatar asked Feb 28 '11 18:02

Yottagray


1 Answers

All 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');
like image 77
Pointy Avatar answered Sep 23 '22 01:09

Pointy