WebMasterCampus
WEB DEVELOPER Resources

jQuery Check if Checkbox Is Checked

Learn how to use jQuery to Check if Checkbox Is Checked


jQuery Check if Checkbox Is Checked

If you want to find out user checked on checkbox or checkbox array it easy to find using jQuery. Let’s check the following example.


<fieldset id="checkboxArray">
  <input type="checkbox" name="chk[]" value="US" /> U.S
  <input type="checkbox" name="chk[]" value="Canada" /> Canada
  <input type="checkbox" name="chk[]" value="Australia" /> Australia
</fieldset>

<button>Click to find selected countries</button>

<script src="https://code.jquery.com/jquery-git.js"></script>
<script>

    $("button").on("click", function(){

        console.log( $('#checkboxArray input[type="checkbox"]:checked').length );
        console.log( $('input[name="chk[]"]:checked').length );

        if ($('input[name="chk[]"]:checked').length > 0) {
            //This code will only run when atleast one checkbox will be check.


        }

        $("input[type='checkbox']:checked").each(function(){
              //Find all checked checkboxes values
              console.log(this.value);
          });
    });

</script>

</body>
</html>
Created with love and passion.