I have two radio buttons with the same name, one is checked by default. How can you check or uncheck a radio button in jQuery when selecting from id?
I've tried:
$('#radio1').attr('checked','checked');
$('#radio1').attr('checked', true);
Nothing seems to work.. any ideas?
Thank you!
You can not have same id (#radio1
) more than once, use a class
instead.
$('.radio1').attr('checked', true);
$('.radio2').attr('checked', true);
The id
should be used once per element per page.
If you want to check/uncheck on click
however, you may do like:
$('#someid').click(function(){
$('#radio1').attr('checked', true);
});
Or
$('#someid').click(function(){
$('#radio1').attr('checked', this.checked);
});
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