I need to check when an image is loaded. The result has to be something like this:
$('.testimage').onload(function() {
// do stuff
});
All help is appreciated.
I need to check when an image is loaded. The result has to be something like this:
$('.testimage').onload(function() {
// do stuff
});
All help is appreciated.
try this
$('.testimage').load(function() {
// do stuff
});
if you are using jquery version 1.7+
$('.testimage').on('load', function() {
// do stuff
});
There is no onload
method in jQuery (although there is an underlying onload
property on the raw DOM). There is a load
method but it (confusingly) has different meanings (See http://api.jquery.com/load-event/ and http://api.jquery.com/load/ ) depending on the context you use it in, and the version that attaches a load event handler has been deprecated.
The standard jQuery way to attach event handlers is via the on
method:
$('.testimage').on('load', function() {
// do stuff
});
Please try this fiddle
<img src="http://***.**/***/***/book.gif" alt="Book" id="book" width="200">
$('#book').load(function () {
alert('loaded');
});