I have a listener on canvas for whenever I click on it. At certain moments (like when a checkbox is checked) I want to disable that listener and make clicking on it do nothing. How do I do this?

jQuery is allowed.

Recommended Answers

canvas.removeEventListener should work, but only with named functions.

Jump to Post

OK and then how do I had it back?

Not sure what you mean, but if you are adding anonymous functions, you can't remove them (apparently).

Disabling may work, depending on the event I guess.

Jump to Post

All 5 Replies

canvas.removeEventListener should work, but only with named functions.

canvas.removeEventListener should work, but only with named functions.

OK and then how do I had it back?

I just had a thought: Would disabling canvas be enough?

OK and then how do I had it back?

Not sure what you mean, but if you are adding anonymous functions, you can't remove them (apparently).

Disabling may work, depending on the event I guess.

Not sure what you mean, but if you are adding anonymous functions, you can't remove them (apparently).

Disabling may work, depending on the event I guess.

I have this:

handleCanvasMouseDown: function(e){
      this.drawManager.unSelectAllPointsOfTheDrawingThatHasPoints(); 
    },

handling the mouse event on a canvas. A simple if

if it is checked
return false
else if it is not checked
this.drawManager.unSelectAllPointsOfTheDrawingThatHasPoints();

Does not work. It stil continues. And yes, it goes into the checked because a alert does show up.

Autosolved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.