Skip to content Skip to sidebar Skip to footer

Backbone Dynamically Created 'el' Not Binding Events

Like many other users out here I have a problem with el and events. In my situation I have tested multiple solutions including, using the default el (just
)

Solution 1:

Sorry i'm not comfortable with coffeescript, though i think i recognised your event hash

events: {
  "click div" : "testing"
}

and i bet you are trying to bind this testing function to the click on your general view element? there is the problem.

what your click event actually does (selector-wise) is:

$('div', viewElement).click(fn);

meaning, you don't target the viewElement div but div's INSIDE your view element.

if you want to bind to the general view element itself, define an event without a selector

in your case:

events: {
  "click" : "testing"
}

Post a Comment for "Backbone Dynamically Created 'el' Not Binding Events"