I have the following code inside a backbone view:
var BookView = Backbone.View.extend({
initialize: function() {
this.render();
},
render: function() {
this.model.fetch({
success : function(model, resp, opt) {
alert(this.$el.html() ); //THIS ONE DOESN'T WORK?
}
});
alert(this.$el.html() ); // THIS ONE WORKS FINE
}
});
I have two alert(this.$el.html() );
calls, one outside the fetch, and one inside. But for some reason, the one outside the fetch call works, but the one inside the fetch call returns an error:
Uncaught TypeError: Cannot read property 'html' of undefined