check uncheck all checkbox jquery code example

Example 1: how to uncheck a checkbox in jquery

$("#myCheckBox").prop("checked", false);

Example 2: jquery uncheck checkbox

$('#myCheckbox').prop('checked', true); // Checks it
$('#myCheckbox').prop('checked', false); // Unchecks it

Example 3: jquery validate all checkbox checked

<form id="form1" action="/controller/action" method="post">
   <input type="checkbox" name="box1" class="cBox" />
   <input type="checkbox" name="box2" class="cBox" />
   <input type="checkbox" name="box3" class="cBox" />
  <input type="submit" value="Submit" />
</form>
<script>
$('#form1').submit(function() {
   if ($('input:checkbox', this).length == $('input:checked', this).length ) {
            // everything's fine...
   } else {
            alert('Please tick all checkboxes!');
            return false;
   }
});
</script>

Example 4: jquery get all checkbox checked

$('.theClass:checkbox:checked')

Example 5: select all checkboxes jquery

$('input:checkbox').prop('checked', true);

Example 6: select all checkbox jquery

$('#select_all').change(function() {
  var checkboxes = $(this).closest('form').find(':checkbox');
  checkboxes.prop('checked', $(this).is(':checked'));
});