How to Get Selected Checkboxes Id onClick Using jQuery

Last Updated on August 11, 2022 by Roshan Parihar

In this tutorial, learn how to get selected checkboxes id on click using jQuery. The short answer is to use the attr() function with id as its argument. Get the ids of all selected checkboxes or multiple selected checkboxes values or single selected checkbox.

Find the id of a checkbox and get its ids in an array format. Use the array format to get individual IDs using jQuery. You can also find how to allow only a single selection of checkboxes here.

Let’s find out with the examples given below.

Get Selected Checkbox Id Using jQuery(Single Selection Only)

The single selected checkbox allows selecting only one checkbox at a time. You have to use the :checked selector to find the checked checkboxes using jQuery. After that, you have to use the attr() function and pass id as its argument to get the selected checkboxes id on click of the button.

See the below example to find how to get a single selected checkbox id in jQuery.

Output

Virat Kohli
Chris Gayle
Mahendra Singh Dhoni
Sachin Tendulkar
Donald Bradman

Select the above checkbox to get id

You can select only one checkbox at a time from the checkboxes given above. Click any checkbox given above to get its id. On select of a checkbox, you will get its id in the alert box.

Find Multiple Checked Checkboxes Ids in jQuery

If you want to find the ids of the multiple selected checkboxes using jQuery, you have to use the each function to find each selected checkboxes. Now, to get the ids of selected checkboxes in an array format, you have to use the push() with attr(). Also, pass id as the argument of attr().

See the example below to get the ids of multiple selected checkboxes using jQuery.

Output

Virat Kohli
Chris Gayle
Mahendra Singh Dhoni
Sachin Tendulkar
Donald Bradman

Select multiple checkboxes above and click the button to get ids in an array format

To select the multiple checkboxes, you need to press the CTRL button on your keyboard and click the multiple checkboxes. On each click, you will get the ids of checked checkboxes in an array format.

I hope you like this tutorial on how to get selected checkboxes id on click using jQuery.