To set a checkbox as checked with jQuery, the simplest way is to use the jQuery prop() method and to use the ‘checked’ property.

$('#checkbox').prop('checked', true);

If we want to uncheck a checkbox using jQuery, we can use the prop() method and set it to false:

$('#checkbox').prop('checked', false);

Let’s say I have the following HTML:

To set the first checkbox as checked, we can do the following:

$('#checkbox-1').prop('checked', true);

If you are using WordPress, don’t forget to change the $ to jQuery as below:

jQuery('#checkbox-1').prop('checked', true);

How to Set a Checkbox as Checked on Click with jQuery

We can check a checkbox using jQuery very easily by combining the prop() method with a click event.

Let’s say we have the following HTML code and we want to set the checked value of our checkbox as checked in the HTML below:

Check Checkbox

We can utilize both the jQuery click() method and jQuery prop() method to set the checked property of the checkbox.

Below is the Javascript code which will allow us to set our checkbox as checked.

$('#click-me').click(function(){
  $('#checkbox-1').prop('checked', true);
});

The final code and output for this example of how to check a checkbox on click using jQuery and JavaScript is below:

Code Output:

Check Checkbox

Full Code:

Check Checkbox

How to Uncheck a Checkbox Using jQuery

Just as easily as we can check a checkbox, we can also uncheck a checkbox using jQuery.

Let’s say we have the following HTML code and we want to set the checked value of our checkbox as unchecked in the HTML below:

Uncheck Checkbox

We can once again utilize both the jQuery click() method and jQuery prop() method to set the checked property of the checkbox as false.

Below is the JavaScript code which will allow us to set our checkbox as unchecked.

$('#click-me').click(function(){
  $('#checkbox-1').prop('checked', false);
}); 

The final code and output for this example of how to uncheck a checkbox on click using jQuery and Javascript is below:

Code Output:

Uncheck Checkbox

Full Code:

Uncheck Checkbox

Hopefully this article has been useful for you to understand how to check a checkbox and uncheck a checkbox using jQuery.

Categorized in:

jQuery,

Last Update: March 4, 2024