Backbone.js Event Binding

jQuery’s habit of setting this to whatever happens to be convenient at the time is a pretty nasty pattern, in my opinion — fortunately, you never have to rely on it:

onClick: function(e) {
  this;                // Still the view instance (as it should be).
  e.target;            // The element that was clicked.
  e.currentTarget;     // The element that was bound by the click event.
}

… You can use the target or currentTarget of the event object, as appropriate.

Leave a Comment