Fetch certain checkbox values and put them in an array.
I use the following code to store all checked checkbox values into a variable:
- $("#myBtn").click(function () {
-
- var searchIDs = $('input:checked').map(function(){
-
- return $(this).val();
-
- });
- $(".gathering").val(searchIDs.get());
- });
It works, but this code gathers ALL the values of checked checkboxes.
How can I adjust the coding so that only the checkboxes with a certain class in it are 'gathered' ?
For example: I only want to store the values with the class '
myCheckBox' into the variable
- <input type="checkbox" class='myCheckBox' value="11">
- <input type="checkbox" class='not this one' value="31">
- <input type="checkbox" class='myCheckBox' value="44">