I am in the process of rewriting jQuery code to Backbone, but am stuck on a seemingly trivial issue:
Inside an event callback on an element that’s a child of the main View element, how do I access the specific child element that was clicked (for example)?
var Composer = Backbone.View.extend({
events: {
"click #postnow": "postnow"
},
postnow: function(){
// @fixme:
var btn = $("#postnow");
// Do something
}
});
new Composer({el: $('.composer')});
In jQuery, I would use $(this), but in Backbone it refers to the View element, not the clicked child.
Is there any way to do that without explicitly specifying the selector again?
In view callbacks, you have access to the jQuery events and their properties, more specifically to event.currentTarget
Try