How to check or uncheck a checkbox in jQuery

Hi guys! In this tutorial I will explain how you can check or uncheck a checkbox in jQuery by using a button. You will be able to use this function to check or uncheck several checkboxs in a page.

I have created a simple checkbox input with two buttons(Check and Uncheck):

<input type="checkbox" id="checkbox">
<input type="button" id="check" value="Check">
<input type="button" id="uncheck" value="Uncheck">

Next, I will write a jQuery function:

$("#check").click(function() {

$("#checkbox").attr("checked","checked");  // this code will check the checkbox when I click on the Check button

});

Next, I will write a jQuery function to Uncheck the checkbox:

$("#uncheck").click(function() {

$("#checkbox").removeAttr("checked");  // this code will uncheck the checkbox when I click on the Uncheck button

});

In this way you can check and uncheck a checkbox in a simple way!

Video tutorial:









Leave a Comment