0
canvas.addEventListener('click', function(evt) {
        var mousePos = getMousePos(canvas, evt);
    
        if (isInside(mousePos, startButtonClick)) {
            startGame();
        }else{
            
        }   
    }, false);

Hey guys I just quickly wanted to know how I can remove this event listener and asked here. I hope the way I asked was right, if now im sorry!

Shikkuu
  • 11
  • 1
  • This is interesting. There is a method `removeEventListener()` but it only works with named functions. Since you used `addEventListener()` passing it an anonymous function, there is no way to use it. https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener - https://stackoverflow.com/questions/4950115/removeeventlistener-on-anonymous-functions-in-javascript – GrafiCode May 27 '22 at 14:06
  • Even jQuery's `unbind()` fails to remove an event listener bound with `addEventListener()`: https://stackoverflow.com/questions/18947653/remove-event-listener-from-window-object-using-jquery#:~:text=jQuery%20can%20only%20unbind%20all,that%20specifies%20the%20callback%20function. – GrafiCode May 27 '22 at 14:09

0 Answers0