There's a situation with my button elements where I want them to stop being clickable once a certain condition is met. I thought using the removeEventListener function would work, but even after my if statement evaluates to true, the buttons remain interactive.
const field = Array.from(document.querySelectorAll(".field"))
const boardData = [];
field.forEach(button => {
const func = (e) => {
if(xTurn) {
if(checkWin(player1)){
freezeBoard(field,func)
};
}
else {
if(checkWin(player2)){
freezeBoard(field,func)
};
}
}
button.addEventListener("click", func)
})
function freezeBoard(buttons,func) {
buttons.forEach(button => {
button.removeEventListener("click", func);
})
}