I'm new to Backbone and trying to do some examples, but I'm stuck with this one. I have the below BackBone View:
CommentBoxView = Backbone.View.extend({
initialize: function () {
this.render();
},
render: function () {
var template = _.template( $("#comment_box_template").html(), {} );
this.el.html(template);
},
events: {
"keypress textarea": "doKeyPress"
},
doKeyPress: function (event) {
console.log(event);
}
});
Everything's running ok but if I replace
this.el.html(template);
with this:
this.el = $(template).replaceAll(this.el);
The keypress event is not fired at all. Could anyone please explain to me why it happened and how to make this code works? Thank you all very much.