Reputation: 271884
<input type="radio" name="sort" value="2" id="myradio">
How do I make this checked in JQUERY?
Upvotes: 12
Views: 28614
Reputation: 324597
Really, there's no need for jQuery here: it will be slower, introduce a needless framework dependency and increase the possibility of error. The DOM method for this is also as clear and readable as it could be, and works in all the major browsers back to the 1990s:
document.getElementById("myradio").checked = true;
If you must use jQuery then I'd stop at just using it to get hold of the element:
$("#myradio")[0].checked = true;
Upvotes: 6
Reputation: 28411
In addition to using id...
$('input[name="sort"]').attr('checked',true);
$('input[value="2"]').attr('checked',true);
Upvotes: 5