checkbox checked in jquery code example

Example 1: jquery set checkbox checked

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

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

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

Example 3: How to check whether a checkbox is checked in jQuery?

//using plane javascript 
if(document.getElementById('on_or_off_checkbox').checked) {
    //I am checked
} 

//using jQuery
if($('#on_or_off_checkbox').is(':checked')){
    //I am checked
}

Example 4: jquery if checkbox checked

$( "SELECTOR" ).attr( "checked" )  // Returns ‘true’ if present on the element, returns undefined if not present
$( "SELECTOR" ).prop( "checked" ) // Returns true if checked, false if unchecked.
$( "SELECTOR" ).is( ":checked" ) // Returns true if checked, false if unchecked.

Example 5: jQuery check a radio button

// jQuery version 1.6 or above use:  
$("#myRadioID").prop("checked", true);
 
//jQuery versions below 1.6 use:
$("#myRadioID").attr('checked', 'checked');

Example 6: jquery checkbox checked

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