DEV Community

Cover image for How to Check if Image is Loaded or not in jQuery?
Code And Deploy
Code And Deploy

Posted on

4 2

How to Check if Image is Loaded or not in jQuery?

Originally posted @ https://codeanddeploy.com visit and download the sample code:
https://codeanddeploy.com/blog/jquery/how-to-check-if-image-is-loaded-or-not-in-jquery

In this post, I will show you an example of how to check if the image is successfully loaded using jquery. If you need to check if the image is loaded on page load then this post is for you. Sometimes we need to check and display to the user if a specific image element was loaded successfully.

Here is the code example:

<script type="text/javascript">
    $('.your_image_class')
    .load(function(){
        console.log("Image loaded succesfully!");
    })
    .error(function(){
        console.log("Error occurred when loading image.");
    });
</script>
Enter fullscreen mode Exit fullscreen mode

I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/jquery/how-to-check-if-image-is-loaded-or-not-in-jquery if you want to download this code.

Happy coding :)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series