Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  196] [ 6]  / answers: 1 / hits: 17228  / 12 Years ago, mon, september 10, 2012, 12:00:00

I have the falling events hash -



events:
'click #someButton : 'someFunction'


To close the view I have tried



close:
$(#someButton).unbind(click)


and



   `close:

$(#someButton).remove()`


But someFunction is still being fired more than once. How do I unbind this event from the button?



I've also tried



$(@el).find(#someButton).unbind(click) as well 

More From » events

 Answers
4

Backbone.js view events are delegated to the view's el (so there is no event bound to your #someButton element but rather when a click event bubbles up to the el it checks to see if the event came from an element matching that selector), that being the case to remove the event you need to remove it from the el, for example



  $(this.el).off('click', '#someButton');


If you want to remove all delegated events you can just use the view's undelegate method


[#83147] Sunday, September 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elishaannac

Total Points: 28
Total Questions: 97
Total Answers: 101

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
elishaannac questions
Sun, Dec 5, 21, 00:00, 3 Years ago
Mon, Jun 14, 21, 00:00, 3 Years ago
Mon, Jul 22, 19, 00:00, 5 Years ago
Mon, Jul 8, 19, 00:00, 5 Years ago
;