I am trying to add or remove EventListener using the following code.
function a(input) {
var b = document.getElementsByClassName("class_name");
if (input == "add"){
for (let i = 0; i < 5; i++){
b[i].addEventListener("click", c); // This is working!
}
}
if (input == "remove"){
for (let i = 0; i < 5; i++){
b[i].removeEventListener("click", c); // This is not working!
}
}
function c(d){
random_function(e); // "e" is a global variable
e = d.currentTarget.getAttribute("id");
random_function(e); // Running again the same function
}
}
addEventListener works as expected, but removeEventListener is not working. Why is that?