I have following script to remove images that are too small but it doesn't work properly, first time I load the page, every image gets replaced with no-image.png
, after I refresh page it works properly, what am I missing here?
$(document).ready(function () {
$('.story-img').error(function () {
$(this).attr("src", "/Images/no-image.png");
$(this).css('border', 'none');
});
$(".story-img").each(function () {
var theImage = new Image();
theImage.src = $(this).attr("src") || $(this).src;
var imageWidth = theImage.width;
var imageHeight = theImage.height;
if (imageWidth < 32 || imageHeight < 32 || $(this).height() < 32 || $(this).width < 32) {
$(this).attr("src", "/Images/no-image.png");
$(this).css('border', 'none');
}
});
});