How can I check if a background image is loaded?

The Solution to How can I check if a background image is loaded? is


try this:

$('<img/>').attr('src', 'http://picture.de/image.png').on('load', function() {
   $(this).remove(); // prevent memory leaks as @benweet suggested
   $('body').css('background-image', 'url(http://picture.de/image.png)');
});

this will create new image in memory and use load event to detect when the src is loaded.

~ Answered on 2011-02-20 16:31:18


Most Viewed Questions: