I am trying to detect if the image is available in javascript
.
I have a switch statement which return different type of images.
switch (type){
case 'oldProduct':
return "<img src='project/'" + folder + imagename + "/>"
break;
case 'newProduct':
return "<img src='project/'" + folder2 + imagename2 + "/>"
break;
more cases....
}
I was wondering if there are anyways to detect if the images exist before I return the image. <img src='project/'" + folder2 + imagename2 + "/img> src
could be a broken path in my case. Thanks a lot!