How to verify background (css) image was loaded? How to verify background (css) image was loaded? javascript javascript

How to verify background (css) image was loaded?


The only way I know of to do this is to load the image using Javascript, and then set that image as the backgroud.

For example:

var bgImg = new Image();bgImg.onload = function(){   myDiv.style.backgroundImage = 'url(' + bgImg.src + ')';};bgImg.src = imageLocation;


Give the class to a div with visibility:hidden at the initial page load. That way, it'll already be in the browser cache when you assign the class to your table cell.


@Jamie Dixon - he didn't say he wanted to do anything with the background image, just know when it's loaded...

$(function( ){    var a = new Image;    a.onload = function( ){ /* do whatever */ };    a.src = $( 'body' ).css( 'background-image' );});