I'm trying to add load
event to img
tag when the src
of the image is changed. The image
is deleted and reattached due to a plugin, so I can't really changed that. This is my simplified HTML
<div class="twitter">
<img src="picture.jpg" />
</div>
And this is my Backbone script
var TwiterView = Backbone.View.extend( {
render : function() {
var self = this;
this.$el.on('load', 'img', function() {
self.updateTwitterPreview();
}).each(function() {
if(this.complete) $(this).trigger('load');
});
this.$el.find('img').on("remove", function () {
alert("Element was removed"); // This one got fired when the event is removed
});
return this;
},
updateTwitterPreview: function() {
alert('test'); // This one got fired when the page is loaded the first time, but not when the image is changed
}
});
I'm trying to use delegated event but it didn't really work.