I'm not sure why my function is not returning data.
loadingImages = function (id)
{
var totalImages = $(id+" img").length;
var imagesLoaded = 0;
var result = null;
$(id).find('img').each(function(elem) {
var fakeSrc = $(this).attr('src');
$(this).attr("src", fakeSrc).load(function() {
imagesLoaded++;
if (imagesLoaded >= totalImages) {
result = true;
} else {
result = false;
}
console.log(result);
});
});
return result;
}
var $id = "#elem";
var rr = loadingImages($id);
console.log(rr);
Any help would be appreciated, this is just personal studying code so I'm in no rush.