jQuery checkbox check-uncheck

jQuery .prop() gets or sets the value of a property for the target element;


    $('.check-all').click(function() {
        $('.checkbox input').prop('checked', true); // check all checkboxes
        $('.radio input').prop('checked', true); // check first radio
    $('.uncheck-all').click(function() {
        $('.checkbox input').prop('checked', false); // uncheck all checkboxes
        $('.radio input').prop('checked', false); // uncheck first radio
    $('.test-checkbox').click(function() {
        if ($('.checkbox:first input').is(':checked')) {
        } else {


<form class="well">
    <p class="help-block">
        <button class="btn check-all">check all checkboxes and radio</button>
        <button class="btn uncheck-all">uncheck all checkboxes and radio</button>
        <button class="btn test-checkbox">test first checkbox</button>
    <label class="checkbox">
        <input type="checkbox"> checkbox 1 
        <strong class="label test-log"></strong>
    <label class="checkbox">
      <input type="checkbox"> checkbox 2
    <label class="radio">
      <input type="radio" name="radio"> radio 1
    <label class="radio">
      <input type="radio" name="radio"> radio 2

Leave a Comment