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",

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s