jQuery Introduction | Controlling Input Elements | Checkbox

Checking Whether a Checkbox Is Selected

Check whether a checkbox with the same id is selected. Returns true or false.

$("#chkBox").is(":checked");
$("input:checkbox[id='chkBox']").is(":checked");

Recommended usage for jQuery 1.6 and later:

$("#chkBox").prop("checked");

Getting the Number of Checkboxes

Get the number of selected checkboxes.

$("#chkBox:checked").length;

Get the total number of checkboxes.

$("#chkBox").length;

Select or Clear All Checkboxes

Select all.

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

Clear all.

$("#chkBox").prop('checked', false);
$("#chkBox").attr('checked', false);

Getting the Values of Checked Checkboxes

$('#chkBox:checked').each(function() { 
    alert($(this).val());
});

Adding an Event When a Checkbox Is Clicked

$("#chkBox").on("click", function() {
    alert('1');
});