Use jQuery to get values of selected checkboxes?

Yes, we can use jQuery to get values of selected checkboxes using the concept of input. We have to also use the :checked selector.


Following is the code −

<!DOCTYPE html>
<html lang="en">
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
<script src=""></script>
<script src=""></script>
   <input type="checkbox" name="checkDemo" id="check1" value="Cricket" />
   <label for="check1">Cricket</label>
   <input type="checkbox" name="checkDemo" id="check2" value="Listening Music" />
   <label for="check2">Listening Music</label>
<input type="checkbox" name="checkDemo" id="check3" value="Reading NewsPaper" />
<label for="check3">Reading NewsPaper</label>
<button type="button">Click Me</button>
   $(document).ready(function () {
      $("button").click(function () {
         $('input[name="checkDemo"]:checked').each(function () {

To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.

This will produce the following output −

Now, select the checkbox −

This will produce the following output on console −

Updated on: 26-Oct-2020


Kickstart Your Career

Get certified by completing the course

Get Started