checkbox checked jquery value 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: 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 3: get value of selected checkbox jquery

$('#checkbox_id:checked').val();
//if checkbox is selected than gets its value

Example 4: jquery checkbox checked value

if ($('#check_id').is(":checked"))
{
  // it is checked
}

Example 5: jquery checkbox set checked

//For jQuery 1.6 and above
$('#myCheckBoxID').prop('checked', true);
//For jQuery Before 1.6
$('#myCheckBoxID').attr('checked','checked');

Example 6: set checkbox checked jquery

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