I 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 JavaScript:
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?
Try this.
In this example, I'm targeting it with its input name and value
Good to know: in case of multi-word value, it will work because of apostrophes, too.
I use this code:
I'm sorry for English.
I've just have a similar problem, a simple solution is to just use:
Any other solution will work if you refresh radio after calling function.