[javascript] How to check a radio button with jQuery?


Try this.

In this example, I'm targeting it with its input name and value

$("input[name=background][value='some value']").prop("checked",true);

Good to know: in case of multi-word value, it will work because of apostrophes, too.


I try to check a radio button with jQuery. Here's my code:

    <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' /> 

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?

I use this code:

I'm sorry for English.

var $j = jQuery.noConflict();

$j(function() {
    // add handler
    $j('#radio-1, #radio-2').click(function(){

        // find all checked and cancel checked
        $j('input:radio:checked').prop('checked', false);

        // this radio add cheked
        $j(this).prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset class="section">
  <legend>Radio buttons</legend>
    <input type="radio" id="radio-1" checked>
    Option one is this and that&mdash;be sure to include why it's great
    <input type="radio" id="radio-2">
    Option two can be something else

Just in case anyone is trying to achieve this while using jQuery UI, you will also need to refresh the UI checkbox object to reflect the updated value:

$("#option2").prop("checked", true); // Check id option2
$("input[name='radio_options']").button("refresh"); // Refresh button set

Short and easy to read option:


It returns true or false, so you can use it in "if" statement.

We should want to tell it is a radio button.So please try with following code.

$("input[type='radio'][name='userRadionButtonName']").prop('checked', true);

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.

The $.prop way is better:

$(document).ready(function () {                            
    $("#radio_1").prop('checked', true);        

and you can test it like the following:

$(document).ready(function () {                            
    $("#radio_1, #radio_2", "#radio_3").change(function () {
        if ($("#radio_1").is(":checked")) {
        else if ($("#radio_2").is(":checked")) {

Try this

var isChecked = $("#radio_1")[0].checked;

try this

 $("input:checked", "#radioButton").val()

if checked returns True if not checked returns False

jQuery v1.10.1

$("#radio_1").attr('checked', true);
$("#radio_1").attr('checked', 'checked');

Yes, it worked for me like a way:

$("#radio_1").attr('checked', 'checked');