i'm trying to check if all images are loaded within a container using the below code
$(document).ready(function () {
$(".slide img").each(function (index) {
var fakeSrc = $(this).attr('src');
$("<img/>").attr("src", fakeSrc).css('display', 'none').load(function () {
alert('loaded');
}).
error(function () {
load_img_Single(fakeSrc);
});
});
function load_img_Single(img) {
alert(img);
var ruth;
$("<img/>").attr("src", img).css('display', 'none').load(function () {
ruth = 'yeap';
}).error(function () {
ruth = 'nope';
});
alert(ruth);
}
});
now as u can see im using a fake container to load the image and check if it has been loaded or not .
im using the .error in the first check of image to see if it was loaded properly or not , if not it executes the function load_img_Single(image) function of mine to load it again.
now in that function again im checking if it was loaded or not . but the problem is the variable 'ruth' is not getting set to anything within that function. its been declared outside but still its coming as 'undefined'.
any insight would be appreciated guys.