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

110
Vistas
forloop div event listeners not adding/removing classes
if (div.id === 'firstDiv')
            {
                div.addEventListener('click', function() {
                        div.classList.remove('w-1/4')
                        div.classList.add('w-full')
                })
            }

I have this code block in a for loop, it checks the id of each div in the loop, and adds an event listener to it. However, while the event listener works if I console.log it, it doesn't actually do anything with the classList

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

0

The id of div is unique to every div so it just work in one div and you didn't defined which div should be change in the classlist so specify it with "this" keyword

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