My class is defined as below:
class NewUser extends Backbone.View
template : JST["backbone/templates/events/new"]
events :
'click button' : 'hello'
hello : ->
alert('hi')
render : ->
@el = $(@template())
@
I initialize the page as follows:
$('body').append(new NewUser().render().el)
Yet when I click the button, no alert displays. Does anyone see anything wrong with my code? The view renders, but the events never register.
You’re creating your
@elin yourrendermethod:but you neglect to call
delegateEvents:So, your events never get bound to the
@elthat you add to the DOM and your button does nothing useful. Yourrendershould look like this: