Jquery success image loaded

Pedro Chagas
Pedro Chagas used Ask the Experts™
on
Hi E's, I have this code to know if the image have any error when loaded:
jQuery(function($) { 
 $("#logo img,#home img,#contact img").error(function() { 
var which_one = $(this).attr("src");
alert(which_one+" fail"); 
});
});

Open in new window

If I want to know if the image was successfully load, what changes I have to do?

Th best regards, JC
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Manager / Solutions Architect
Commented:
Use the load event handler:
jQuery(function ($) {
    $("#logo img,#home img,#contact img")
    .load(function(){ 
        var which_one = $(this).attr("src");
        alert(which_one + " success");
    })
    .error(function () {
        var which_one = $(this).attr("src");
        alert(which_one + " fail");
    });
});

Open in new window

Pedro ChagasWebmaster

Author

Commented:
Muito obrigado.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial