On Feb 15, 2008 6:55 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > I finally finished it .... > > // detect whether images are on > // and change styles accordingly > jQuery.imagesOn = function(){ > > $('<img src="' + '/images/bgimage.jpg' + '#' + Math.random() + '"/ > >' ).load(function() { > $('#noimages').attr("href", '/styles/gotimages.css'); > $('.imagecheck').html('On'); > }); > > if ( $('.imagecheck').val() != 'On' ) { > $('#noimages').attr("href", '/styles/imagefree.css'); > } > } The problem here is your .load callback will get called at some point in the future, when the image finishes loading. However, the next line will get executed immediately, without waiting for that. While this may work in some cases (perhaps your tests), it may not if the image is too large or if the server is slow in responding, for example. So, I don't think this is a good test. > (hack: there is a hidden paragraph to hold the 'variable') A simple variable here works just as well: var imgOn = false; $('<img src="' + '/images/bgimage.jpg' + '#' + Math.random() + '"/>' ).load(function() { $('#noimages').attr("href", '/styles/gotimages.css'); imgOn = true; }); alert(imgOn); But you have the same problem as above: your alert could very well fire before the image is loaded, and the callback fired. - Richard