While inserting images in HTML pages sometimes the image may fail to load due to:
- Getting the image URL wrong
- poor internet connection
So we may want to check if the image is not loading due to these reasons. To check we can use the below methods
Using attributes of <img> to check weather an image is loaded or not. The attributes we will use are:
- onload: The onload event is triggered when a image is loaded and is executed
- onerror: The onerror event is triggered if an error occurs during the execution
Using the image complete property in HTML DOM
This property returns a boolean value if the image is loaded it returns true else it returns false
Here the variable load checks if the image is loaded or not. If an image is loaded then true is alerted else false is alerted.
- Google Chrome
- Interent Explorer
- Check if a jquery has been loaded or not
- How to Check Twitter Bootstrap is Loaded or not ?
- How to check if a jQuery plugin is loaded?
- How to see the extensions loaded by PHP ?
- How to hide “Image not found” icon when source image is not found?
- How to check whether a value is numeric or not using jQuery ?
- How to check whether a variable is set or not using PHP ?
- How to check whether a script is running under Node.js or not ?
- Convert an image into grayscale image using HTML/CSS
- How to specify an image as a server-side image-map in HTML ?
- Why card images use data-src (not src) for image in Bootstrap 4 ?
- How to check whether a checkbox is checked in jQuery?
- How to check whether an object is a date?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.