Frage

I have a small problem with the following script:

$(document).load('img', function(){
     alert('images have loaded');
})

The alert will pop up after all images have loaded, which is correct. However, the 'img' generates a 404 warning in the console.

GET http://www.website.com/img 404 (Not Found) 
War es hilfreich?

Lösung

You're doing that wrong, right now you're trying to load data with ajax from the URL img, as that's what the load() method does, and that's why you're getting the 404.

Using a delegated event handler like that makes no sense, if you're trying to wait for all external resources (as in images etc.) to load, use window.onload

$(window).on('load', function(){
     alert('images have loaded');
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top