Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda