checkbox jquery code example

Example 1: Setting “checked” for a checkbox with jQuery

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

Example 2: jquery set checkbox

//jQuery 1.6+ use:
$('.checkboxClass').prop('checked', true);
//jQuery 1.5.x and below use:
$('.checkboxClass').attr('checked', true);

Example 3: events on checkbox in jquery

$(document).ready(function() {
    //set initial state.
    $('#textbox1').val($(this).is(':checked'));

    $('#checkbox1').change(function() {
        if($(this).is(":checked")) {
            var returnVal = confirm("Are you sure?");
            $(this).attr("checked", returnVal);
        }
        $('#textbox1').val($(this).is(':checked'));        
    });
});

Example 4: jquery checkbox checked

$("checkbox").is(":checked")

Example 5: checkbox is checked jquery

$(your_checkbox).is(':checked');

Example 6: check a checkbox jquery

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