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 :)

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay