How to check image is loaded using JQuery

How to check image is loaded using JQuery

On document load we will check if images are loaded into browser or not. First we will find those images and on load event of them we will check if they are loaded into browser or not.

$("document").ready(function(){
  
    $("#image1").load(function(){
        $("#result1").text("Image 1 loaded");
    }).error(function(){
        $("#result1").text("Error while loading image 1");
    });
    $("#image2").load(function(){
        $("#result2").text("Image 2 loaded ");
    }).error(function(){
        $("#result2").text("Error while loading image 2");
    });
});

.error function is called when there is problem while loading the image. As you can see in below html code I have given path of image which doesn’t exists. This make to execute error function.

Image Loading Example using JQuery

<html> 
<head>
<title>
Jquery Check is image is loaded
</title>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</script>

<script type="text/javascript" language="javascript">

$("document").ready(function(){
    $("#image1").load(function(){
        $("#result1").text("Image 1 loaded");
    }).error(function(){
        $("#result1").text("Error while loading image 1");
    });
    $("#image2").load(function(){
        $("#result2").text("Image 2 loaded ");
    }).error(function(){
        $("#result2").text("Error while loading image 2");
    });
});

</script>

</head>

<body>

<img
src="http://revenmerchantservices.com/image.axd?picture=WindowsLiveWriter/JQueryAnimateDivHeightandWidth/2B03BC1F/image_thumb.png"
id="image1" />

<img src="xx.jpg" id="image2" />
<br/>
<label id="result1"></label>
<br/>
<label id="result2"></label>

</body>
</html>

How to check image is loaded using JQueryasp net image uploadAsp.net Convert String To ImageAsp.net Convert Image To Base64Jquery image click eventJQuery how to change background imageLearning JqueryBasics of jqueryJQuery Radio Button CheckedJQuery SlideJquery Radio Button Checked

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.