Quantcast
Channel: How to check a radio button with jQuery? - Stack Overflow
Viewing all articles
Browse latest Browse all 34

How to check a radio button with jQuery?

$
0
0

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?


Viewing all articles
Browse latest Browse all 34

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>