This post will discuss how to get the value of a checkbox in JavaScript and jQuery.

1. Using jQuery

With jQuery, you can use the .val() method to get the value of the desired input checkbox. For example:

JS


HTML



Edit in JSFiddle

 
To get the value from a checked checkbox, you can use the :checked to select the right elements.

JS


HTML



Edit in JSFiddle

 
Or even better

JS


HTML



Edit in JSFiddle

 
Note when nothing is selected, it returns undefined.

2. Using JavaScript

In pure JavaScript, you can do like:

JS


HTML



Edit in JSFiddle

 
Using querySelector():

JS


HTML



Edit in JSFiddle

That’s all about getting the value of a checkbox in JavaScript and jQuery.