jQuery: Check if an image is loaded successfully

An easy method to check if an image is loaded successfully using the load function.

You can edit the image source path to generate a loading image error.

<!DOCTYPE html>
<html>
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <title>Check image load</title>      
        <script>
            $(function () {
                $('img').load(function () {
                    $('p').html('image loaded successfully')
                });
            })
        </script>
    </head>
    <body>
        <img src='http://codecrawl.com/code/images/drawing.png'>
        <p>Loading image.....</p>
    </body>
</html>

button

Leave a comment

Leave a Reply