How to check a radio button with jQuery ?
11:32I
try to check a radio button with jQuery. Here's my code:
<form>
<div id='type'>
<input type='radio' id='radio_1' name='type' value='1' />
<input type='radio' id='radio_2' name='type' value='2' />
<input type='radio' id='radio_3' name='type' value='3' />
</div>
</form>
And
the JavasScript:jQuery("#radio_1").attr('checked', true);
Doesn't
work:jQuery("input[value='1']").attr('checked', true);
Doesn't
work:jQuery('input:radio[name="type"]').filter('[value="1"]').attr('checked', true);
Doesn't work:
Do you have another idea? What am I missing?
====================================
anwser:
One more function prop() that is added in jQuery 1.6, that serves the same purpose.
$("#radio_1").prop("checked", true);
0 nhận xét