The below code works great, except I want to access the data returned in my function but the object hasn't finished loading yet so I cannot access the object attributes?
$images = $loaded_data.find('img').filter(function () {
if ($(this).attr('src').match(/\.(jpg|png|gif)$/i)) {
return $(this);
}
})
var $image_first = $images.filter(function () {
var theImage = new Image();
theImage.src = $(this).attr("src");
$(theImage).load(function () {
if (theImage.width > 200) {
goodImages = $(this);
return goodImages;
}
});
}).first();
alert($image_first.attr('src'))
How can I prevent the alert from running until the above code has run?
To explain what I am trying to do.
I am loading in a block of html, filtering it to pull out all images with a width of over 200 then taking the first one and using this as the source URL for a news article.