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

386
Vistas
loop through checkboxes by classname in jquery

I need to loop through the all checkboxs to set the button disable or not. If one of the checkbox is checked, then the button is enable. However it looks like my code didn't loop through the checkbox. The alert inside the each function doesn't shown.I found the looping method on How to loop through group of check boxes that have same class name?

There is my code:

function setButton() {

                alert('line 24');
                var blnDisable = true;

                //https://stackoverflow.com/questions/35506843/how-to-loop-through-group-of-check-boxes-that-have-same-class-name
                $('.chkItem').each(function (index, obj) {
                    if (obj.checked == true) {
                        alert('line 30');
                        blnDisable = false;
                    }

                });
                alert('disable=' + blnDisable);
                    $("#btnDownload").attr("disabled", blnDisable);

            }
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This will make it check to see if any of the check boxes are checked. If so, it will enable the check box, if not it will disable it. Lastly, I assigned it to a function so it can be run on page load. This is important so it will automatically check to see whether the download button should be enabled on page laod.

<input type="checkbox" class="chkItem" />one<br />
<input type="checkbox" class="chkItem" />two<br />
<input type="checkbox" class="chkItem" />three<br />
<button id="btnDownload">download</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>


var checkButton = function () {
    blnDisable = true;

    $('.chkItem').each(function (index, obj) {
        if (this.checked === true) {
            blnDisable = false;
        }
    });

    $("#btnDownload").attr("disabled", blnDisable);
};

$(".chkItem").on("change", checkButton);

checkButton();

</script>
about 4 years ago · Santiago Trujillo Denunciar
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