Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda