This post will discuss how to retrieve values of checked checkboxes in JavaScript and jQuery.

1. Using JavaScript

In pure JavaScript, you can use the checked property to get the checked state of a checkbox. The following code demonstrates this with the getElementsByName() method.

JS


HTML



Edit in JSFiddle

 
Alternatively, you can use the querySelectorAll() method with :checked selector.

JS


HTML



Edit in JSFiddle

 
The above code will return all checked checkboxes in the document. To select the only group of checkboxes with a specific name, you can do like:

JS


HTML



Edit in JSFiddle

2. Using jQuery

With jQuery, you can use an attribute selector like:

JS


HTML



Edit in JSFiddle

 
To join the values of checked checkboxes as a single string separated with a delimiter, you can do like:

JS


HTML



Edit in JSFiddle

That’s all about retrieving checked checkboxes values in JavaScript and jQuery.