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

252
Visualizações
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
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