I'd like to check the radio button with jQuery
<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>
This is my code here
jQuery("#radio_1").attr('checked', true);
jQuery("input[value='1']").attr('checked', true);
jQuery('input:radio[name="type"]').filter('[value="1"]').attr('checked', true);
I tried these methods, but they didn't work. What should I do?
javascript jquery
$("#radio_1").prop("checked", true)
$("#radio_1").attr('checked', 'checked');
You can do it like above. You can use the bottom one when jQuery is less than 1.6 version.
© 2024 OneMinuteCode. All rights reserved.