This post will discuss how to check (or uncheck) checkbox in JavaScript and jQuery.

1. Using jQuery

With jQuery, you can easily check or uncheck the checkbox using the .prop() method. To check the checkbox, set the checked property to true, and to uncheck the checkbox, set the checked property to false.

JS


HTML



Edit in JSFiddle

 
You can also access the underlying HTMLInputElement and set its boolean checked property:

JS


HTML



Edit in JSFiddle

 
Alternatively, you can simulate a mouse-click on a checkbox using jQuery’s click() method.

JS


HTML



Edit in JSFiddle

2. Using JavaScript

With pure JavaScript, you can use the checkbox’s checked property to set the checked state of a checkbox.

JS


HTML



Edit in JSFiddle

 
Alternatively, you can trigger the “click” JavaScript event of checkbox using HTML DOM click() method.

JS


HTML



Edit in JSFiddle

That’s all about checking a checkbox in JavaScript and jQuery.