I want to check if an image exists using jquery.
For example how do I check this image exists
http://www.google.com/images/srpr/nav_logo14.png
the check must give me a 200 or status ok
————–edited——————-
var imgsrc = $(this).attr('src');
var imgcheck = imgsrc.width;
if (imgcheck==0) {
alert("You have a zero size image");
} else { //do rest of code }
Thanks
Jean
Use the
errorhandler like this:If the image cannot be loaded (for example, because it is not present at the supplied URL), the alert is displayed:
Update:
I think using:
would be enough to check for a 404.
More Readings:
Update 2:
Your code should be like this:
No need for these lines and that won’t check if the remote file exists anyway: