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

251
Vistas
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 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