Asynchronously load images with jQuery

No need for ajax. You can create a new image element, set its source attribute and place it somewhere in the document once it has finished loading: var img = $(“<img />”).attr(‘src’, ‘http://somedomain.com/image.jpg’) .on(‘load’, function() { if (!this.complete || typeof this.naturalWidth == “undefined” || this.naturalWidth == 0) { alert(‘broken image!’); } else { $(“#something”).append(img); } … Read more

jQuery callback on image load (even when the image is cached)

If the src is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete, like this: $(“img”).one(“load”, function() { // do stuff }).each(function() { if(this.complete) { $(this).load(); // For jQuery < … Read more