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

191
Vistas
Javascript add and delete class on a button on click

I'm trying to create a button click event. I usually use a value to check whether the button is already clicked, but some buttons have a different kind of value:

if (quizUrl.indexOf(tgt.value) === -1) {
   if (tgt.value === 'Negeren') {
       el.ClearArray(quizUrl)
       if (tgt.classList.contains('activeMulti')){
           tgt.classList.remove('activeMulti');
       } else {
           tgt.classList.add('activeMulti');
       }
   } else {
       quizUrl.push(tgt.value);
       for (let i = 0; i < buttons.length; i++) {
           buttons[i].classList.add('activeMulti');
       }
   }
}
                    

I've searched for a while but I couldn't find anything that worked or wasn't JQuery. The problem is about the part:

if (tgt.value === 'Negeren') {

Which means if the targeted value = negeren check if it has a certain class. If it has delete that class and if it hasn't add it. This should work like an on and off button, but for some reason it won't add the class and if I delete the else it adds it, but afther it does nothing. Does anybody know a solution?

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