In the code snippet below, from my jQuery setup, I need to check if the image file really exists, and if not, I would like to replace the default image. Currently, if the file does not exist, I just get a broken swatch ...
$('#myTheme').change ( function() { var myImage = $('#myTheme :selected').text(); $('.selectedImage img').attr('src','../wp-content/themes/myTheme/styles/'+myImage+'/screenshot.jpg'); //if screenshot.jpg does not exist, use "../../default.jpg" instead } );
jquery
Scott B
source share