I have a list that looks like this:
<ul>
<li>nameID0001</li>
<li>nameID0002</li>
<li>nameID0003</li>
<li>nameID0004</li>
</ul>
I know there is a photo associated with the name. It is 'nameID0001.jpg' or 'nameID0001.png'.
I want to insert a picture after name:
$('ul li').each(function () {
var nameID = $(this).text();
$(this).append('<img src="/images/' + nameID + '.jpg" alt="" />');
});
How to recognize whether a file exists and whether it has a jpg or png extension.
If it doesn't exist insert 'default.jpg', otherwise insert with the appropriate extension.