I'm trying to replace the image when it encounters error on the initial src by using this...
$(".thumbnails").on("error", function () {
if ($(this).attr("src") != "/assets/img/img-error.jpg") {
$(this).attr("src", "/assets/img/img-error.jpg");
}
});
It's working fine on images that has been loaded during page load..however when I got images appended in a modal
or popover
it didn't trigger the function even though I'm using .on() delegation
I also tried using this but it didn't do the function even on images during page load..
$(document).on("error", ".thumbnails", function () {
if ($(this).attr("src") != "/assets/img/img-error.jpg") {
$(this).attr("src", "/assets/img/img-error.jpg");
}
});