I am trying to remove an event listener with bound variables from a different function from where the listener was set.
I have already sen this post that describes how to remove a bound listener from within the same function, which is different from what I am trying to do:
function testBind(var1,var2){
//remove the bound event from within this function <<<
alert('bound event now removed');
}
function setEvent(){
var addEvent = document.getElementById("testBtn");
var boundYes = yesFunction.bind( this, this );
addEvent.addEventListener('mouseup', boundYes);
}
All of the examples I found have the event listener being removed inside the same function where the event listener is set:
addEvent.removeEventListener("mouseup", boundYes );
I understand that using bind creates a new event listener every time and to remove the listener you need to set and remove it by the same variable.
How can I properly remove the event listener from the testBind
function?