Question

Hi everyone in my main html file, I have this div that some img are define in it:

< div id="preload">
    < img src="http://howindia.com/......jpg" width="1" height="1" /> 
< /div>

and in my .js file I said:

$("#preload").load(function(){
    alert("something...");
    //call other functions 
});

but simply loading all images into the < div id="preload"> won't trigger any event and

Was it helpful?

Solution

The image load event does not propagate to the div. Try adding a load handler to the image(s) instead.

Example fiddle

$("#preload img").load(function(){
    alert("something...");
    //call other functions 
});

OTHER TIPS

First off, a quick tip. If a library used by thousands (millions?) of people was "not working" chances are it wouldn't be you who noticed it. Its 100% more likely in this situation that it's your code not working, not jQuery.

As for your issue, a quick look at the documentation for load() shows no overload taking a function as the first parameter. It is defined as:

.load( url, [ data ], [ complete(responseText, textStatus, XMLHttpRequest) ] )

Are you maybe really trying to use .ready()

Or perhaps the .load() event, in which case the documentation specifies

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

use this :

$(document).ready(function() {
  // do what u want.
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top