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

282
Vistas
How can I check with JQuery if a checkbox is checked and if so add a class to the parent label?

I would like, on load of the page, to check if a checkbox is :checked Then if it is, add a class to the label. I currently have the following script but it doesn't work.

$(document).ready(function() {
    $('input').is(':checked') {
        $(this).parent('label').toggleClass('label--active');
    });
});

My HTML is:

<label class="container-checkbox" for="checkOne">
    <span class="checkbox-label">Option one</span>
    <input type="checkbox" id="checkOne">
    <span class="checkmark"></span>
</label>

I can not change the DOM order as these are custom checkboxes.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I guess you can use this:

$(document).ready(function() {
    let checkboxone = document.getElementById('checkOne');
  checkboxone.addEventListener('change',function() {
    checkboxone.parentNode.classList.toggle('label--active');
  });
});

How does is work?

Everytime when the checkbox is clicked, the class 'label--active' will be added / removed.

about 4 years ago · Juan Pablo Isaza 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