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.