We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,870 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to "undo" a listener?

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.

2
Contributors
5
Replies
4 Hours
Discussion Span
3 Months Ago
Last Updated
22
Views
Related Article: Proper way to do JavaScript-based OAuth is a JavaScript / DHTML / AJAX discussion thread by Dani that has 4 replies, was last updated 3 months ago and has been tagged with the keywords: oauth.
riahc3
 
Team Colleague
1,295 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

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

pritaeas
Posting Prodigy
Moderator
9,268 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

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?

riahc3
 
Team Colleague
1,295 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

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.

pritaeas
Posting Prodigy
Moderator
9,268 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

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.

riahc3
 
Team Colleague
1,295 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

Autosolved.

riahc3
 
Team Colleague
1,295 posts since May 2008
Reputation Points: 62
Solved Threads: 13
Skill Endorsements: 11

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0568 seconds using 2.49MB