Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unbind Backbone View Events

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 
like image 294
praks5432 Avatar asked Sep 10 '12 21:09

praks5432


1 Answers

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

like image 161
Jack Avatar answered Oct 02 '22 23:10

Jack