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