I have 2 elements, one nested in the other. (Its a modal dialog box). When a user click the outer element, a function closeModal
should be triggered, if the user click on a li
within the inner elements (its children), another function like
should be triggered.
Problem: I looked at other solutions and tried applying to my backbone.js View, but it does not seem to work. Is there something different that has to be changed?
View
ModalShowItemView = Backbone.View.extend({
el: '#modal_show_item',
events: {
'click div#modal': 'closeModal',
'click li#like' : 'like'
},
initialize: function() {
this.render();
this.clickHandler();
},
render: function() {
$(this.el).show().append( this.template( this.model.toJSON() ) );
},
clickHandler: function() {
var self = this;
$(this.el).click(function(e) {
if(e.target == self) {
self.closeModal();
}
});
},
closeModal: function() {
console.log('closemodal');
},
like: function() {
console.log('like');
}
});