Setting “checked” for a checkbox with jQuery
snippet in javascript

Setting “checked” for a checkbox with jQuery

user6196

$("#mycheckbox")[0].checked = true;
$("#mycheckbox").attr('checked', true);
$("#mycheckbox").click();

Setting “checked” for a checkbox with jQuery

user1972

$('#checkboxid').get(0).checked = true;  //For checking

$('#checkboxid').get(0).checked = false; //For unchecking

Setting “checked” for a checkbox with jQuery

user3383

$("#check").on("click", function () {

    var chk = document.getElementById('check').checked;
    var arr = document.getElementsByTagName("input");

    if (chk) {
        for (var i in arr) {
            if (arr[i].name == 'check') arr[i].checked = true;
        }
    } else {
        for (var i in arr) {
            if (arr[i].name == 'check') arr[i].checked = false;
        }
    }
});

Setting “checked” for a checkbox with jQuery

user3986

$('input[name *= ckbItem]').prop('checked', true);

Setting “checked” for a checkbox with jQuery

user8758

$("input.myclass[name='myname'][value='the_value']").prop("checked", true);

Setting “checked” for a checkbox with jQuery

user962

if ($('#myCheckBox:checked').val() !== undefined)
{
    //Checked
}
else
{
    //Not checked
}

Setting “checked” for a checkbox with jQuery

user1046

$('span.ui-[controlname]',$('[id]')).text("the value");

Setting “checked” for a checkbox with jQuery

user8745

$("#checkbox1").prop('checked', false).checkboxradio("refresh");

Setting “checked” for a checkbox with jQuery

user9731

$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);

Setting “checked” for a checkbox with jQuery

user978

$('controlCheckBox').click(function(){
    var temp = $(this).prop('checked');
    $('controlledCheckBoxes').prop('checked', temp);
});

Setting “checked” for a checkbox with jQuery

user3084

    var c = $("#checkboxid");
    if (c.is(":checked")) {
         $('#checkboxid').prop('checked', false);
    } else {
         $('#checkboxid').prop('checked', true);
    }

Setting “checked” for a checkbox with jQuery

user5170

var elements = document.getElementsByClassName('myCheckBox');
for(var i = 0; i < elements.length; i++)
{
    elements[i].checked = true;
}

Setting “checked” for a checkbox with jQuery

user8837

    // when the button (select_unit_button) is clicked it returns all the checed checkboxes values 
    $("#select_unit_button").on("click", function(e){

             var arr = [];

             $(':checkbox:checked').each(function(i){
                 arr[i] = $(this).val(); // u can get id or anything else
             });

              //console.log(arr); // u can test it using this in google chrome
    });

Setting “checked” for a checkbox with jQuery

user5465

$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);

check a checkbox jquery

user4216

$('#grepperRocks').prop('checked', true);