This post will discuss how to check/uncheck all checkboxes in JavaScript and jQuery.

1. JavaScript Solution

A checkbox’s state can be changed using the HTMLInputElement’s checked attribute. To check or uncheck all checkboxes, you can set the checked attribute individually for each checkbox.

JS


HTML


CSS



Edit in JSFiddle

2. jQuery Solution

With jQuery, you can do like:

JS


HTML


CSS



Edit in JSFiddle

 
Alternatively, you can simulate a mouse-click for all checkboxes using jQuery’s click() method.

JS


HTML


CSS



Edit in JSFiddle

 
Another solution is to set the checked attribute using the prop() method.

JS


HTML


CSS



Edit in JSFiddle

That’s all about checking or uncheck all checkboxes with JavaScript and Query.