jQuery Check the image is Available / Exist
jQuery Check the image is  Available / Exist

awproject.net – In some case we need check image is available or not. In example we want to replace image become HD image with 2x resolustion of default image.

Before replace the default image, we need to check first is the image available. So if the image available the jQuery script replace the default image, if not available not do anything.

So, this is this is jQuery script to check image available or not.

1. First step is load jQuery script library. Place on footer before </body> tag

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

2. This is the script to check the image is available

var image = new Image();
image.src = 'https://domain.com/image.png';

image.onload = function(){
  // Do something if the image available
  alert('Image available');
};

Thanks :mrgreen: any question? leave comment below … sorry my bad english.

widhy980

Blogger, Web Developer & Traveler

Hi, I am from Indonesia, and i have more interest about website development. i have good skill on Codeigniter, Wordpress, HTML x CSS and Bootstrap. have a business? please contact me ... :D

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *