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

249
Views
element.classList.add not working did I do something wrong?

code:

try {
            let before_column = allColumns[allColumns.indexOf(current_column) - 1].children;
            if (before_column[current_postition - 2] != undefined && before_column[current_postition - 2].children.length != 0) {
                if (before_column[current_postition - 2].children[0].className.split(" ")[1] == "blackpiece") {
                    before_column[current_postition - 2].classList.add("attackedwhite");
                    knightAttacked.push(before_column[current_postition - 2]);
                }
                if (before_column[current_postition - 2].children[0].className.split(" ")[1] == "whitepiece") {
                    before_column[current_postition - 2].classList.add("protectedwhite");
                    knightProtected.push(before_column[current_postition - 2]);
                }
            }
            else {
                before_column[current_postition - 2].classList.add("protectedwhite");
                knightProtected.push(before_column[current_postition - 2]);
            }
        }

        catch (er){
            console.log(er);
        }

Error:

TypeError: before_column[(current_postition - 2)].classList.add is not a function

I know about the toggle function but I need the add to work my project requires the add function and can't be done with the toggle function. Any help is much appreciated.

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!