Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a window's onclick event (Pebble.js)

Tags:

pebble-js

I am writing a Pebble app in Pebble.js which needs to run different functions when the same button is pressed at different times throughout the app.

I can easily associate a function with a button:

dispWindow.on('click', 'up', function(e) {
  doSomething();
});

After doSomething runs a few times, I need to change what happens when the user clicks the "up" button in the dispWindow Window. I can add this code:

dispWindow.on('click', 'up', function(e) {
  doSomethingElse();
});

However, when the user clicks the "up" button, doSomething and doSomethingElse both fire. How do I remove doSomething from the "up" button?

like image 942
dybm Avatar asked Dec 08 '25 07:12

dybm


1 Answers

You can use the off event, like this:

dispWindow.off('click');

Then, call the on event again after that:

dispWindow.on('click', 'up', function(e) {
  doSomethingElse();
});
like image 192
Ryan K Avatar answered Dec 12 '25 12:12

Ryan K