javascript - jquery radio button checked event - How to check a radio button with jQuery?

13 Answers

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.

check radio button is checked or not in jquery

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?

Short and easy to read option:


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

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")) {

You have to do

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

That's the HTML attribute

Yes, it worked for me like a way:

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

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

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

Try this

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

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:

$(function () {
    $('#CostAnalysis input[type=radio]').click(function () {
        var value = $(this).val();

        if (value == "Supply & Lay") {
            $('#ul-suplay').append('<fieldset data-role="controlgroup"> \

Try this with example

<script src=""></script>
<form id="myForm">
<input type="radio" name="radio" value="first"/> 1 <br/>
<input type="radio" name="radio" value="second"/> 2 <br/>

$(document).ready(function () {
    $('#myForm').on('click', function () {
        var value = $("[name=radio]:checked").val();


try this

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

if checked returns True if not checked returns False

jQuery v1.10.1

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.

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

attr accepts two strings.

The correct way is:

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