Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
How to store the values of all checked checkboxes with the same class name in an array?

I've been through all of the posts here and none worked so far. I have list of checkboxes with the same class:

<input class="my_checkbox" type="checkbox" value="some_value1">
<input class="my_checkbox" type="checkbox" value="some_value2">
<input class="my_checkbox" type="checkbox" value="some_value3">

I can either toggle them individually or use a toggle button that checks/uncheck all:

$(document).on('click', '#toggle_button', function () {
    if ($(this).prop("checked")) {
        $(".my_checkbox").prop("checked", true);
    } else {
        $(".my_checkbox").prop("checked", false);
    }
});

Now I want to get all the values into an array, and I've tried multiple things and none worked, the array always ends up empty.

I tried:

$('input:checkbox.my_checkbox').each(function () {
     arr.push($(this).val());
});

and:

$('.my_checkbox:checkbox:checked').map(function() {
     arr.push($(this).val());
}).get();

And some more, but nothing seem to work

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!