Backbone click event not firing

backbone-events, backbone.js, coffeescript

Solution

From the fine manual:

delegateEvents `delegateEvents([events])`

[...] Events are written in the format `{"event selector": "callback"}`. The `callback` may be either the name of a method on the view, or a direct function body. Omitting the `selector` causes the event to be bound to the view's root element (`this.el`).

So you want your `events` to look like this:

events:
    'click': -> console.log('clicked')

Demo: http://jsfiddle.net/6W6QE/

Problem

So I have a Backbone view in which I declare it's className. I'm trying to bind a click event to that class. So something like this: ``` className: "question" events: "click .question": -> console.log("clicked") ``` This doesn't seem to work. It seems to be because the element isn't inside the view itself. So if I create an element within a template, I can bind to that just fine. I should be able to bind to the view itself right? Any help is appreciated. Thanks!

Original source