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

243
Vistas
Modifying classList in event handler in React component

What I am trying to achieve with this is quite simple. I have an array of options/tags displayed in a div. I want the classes to change on click to simulate an "active" state. While I've seen a few snippets on codesandbox that I could use to achieve what I want, my curiosity still is why this wouldn't even trigger the class change.

The referenced event elements and id match...

const variantHandler = (e: any) => {
    e.preventDefault()
  
const d = e.currentTarget

const c = () => {
    variants.map((variant: any) => {
        if (d.id !== variant.node.id) {
            d.classList.remove('bg-gray-900', 'text-myGray', 'dark:bg-myGray', 'dark:text-gray-900')
            //alert('reached remove')
        }
        else {
            d.classList.add('bg-gray-900', 'text-myGray', 'dark:bg-myGray', 'dark:text-gray-900')
            //alert('reached add')
        }
    })
}
c();
}
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