Question

I need to make this function have the ability to have an add event listener and remove event listener

canvas2 was $('canvas') but i changed it to make it easier to use

canvas2.mousedown(function(e){handleMouseDown(e);});

because this does not have an event listener

Was it helpful?

Solution

Wild guess: You want

canvas2.on("mousedown", handleMouseDown);
…
canvas2.off("mousedown", handleMouseDown);

With the unnecessary anonymous function you did not have a reference to the actual passed listener, so you could not remove it any more.

when the function has been used the function needs to be disengaged

You might also consider using .one("mousedown", handleMouseDown), then.

OTHER TIPS

You need to say either

canvas2.onmousedown=function(e){
     handleMouseDown(e);
});

or

canvas2.addEventListener('mousedown',function(e){
     handleMouseDown(e);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top