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?
Yes, it worked for me like a way:
We should want to tell it is a
radio
button.So please try with following code.For versions of jQuery equal or above (>=) 1.6, use:
For versions prior to (<) 1.6, use:
Tip: You may also want to call
click()
orchange()
on the radio button afterwards. See comments for more info.Try this with example
I got some related example to be enhanced, how about if I want to add a new condition, lets say, if I want colour scheme to be hidden after I click on project Status value except Pavers and Paving Slabs.
Example is in here:
http://jsfiddle.net/m7hg2p94/4/