Code error fixed #3: Backbone event click on id not firing

Hours gone. It’s 3:37AM. Even though it worked for a couple of days, suddenly clicking on a div called ‘about’ was failing to execute. Turned out I had moved it to ‘main-header’ for stylistic purposes and didn’t put two and two together that I had specified ‘main-container’ as the element for this particular view. Since ‘about’ no longer existed in ‘main-container’, the event wasn’t binding to anything. Duh. It feels as bad as having made a typo. But maybe posting this will save 3+ hours in the life of some other Backbone newbie someday.

var LinkView = Parse.View.extend({
el: "#main-container",
initialize: function(tag) {
blah=tag;
if (!(tag)) {tag = 'blah'};
$('#main-header').append(_.template($('#blah-header-template').html(),({"blahName":tag})));
new blahView(tag);
},
events: {
"click #about" : "showProfile"
},
showProfile: function(e) {
new ProfileView(blah);
}
});

Solution:

el: "#main-header",

Advertisement