javascriptbackbone.jsbackbone-events

Backbone js: register view events on parent element


I'd like to register view events on the view parent element. I tried the parent selector:

var MyView = Backbone.View.extend({
  events: {
    'mousemove :parent': 'mousemove'
  },
  // ...
});

But it is not working. How can I achieve this?


Solution

  • Backbone uses jQuery event delegate, so you can't delegate events to the parent node.

    see in Backbone source code line 954, the View.delegateEvents function.