Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!