title: Condition to display image in Javascript
body: <p>I'm looking for create a small javascript code to display images if their src is valid.</p>
  
  <p>I have to separate the script to the html page for better organisation.</p>
  
  <p>Here is what I did :
  HTML</p>
  
  <pre><code>&lt;img id="thmb" src= "http://blog.lefigaro.fr/bd/img-sanctuaire.png" width="50px" height="50px" alt="" ;&gt;
  </code></pre>
  
  <p>JavaScript</p>
  
  <pre><code>var thumbnail = document.images.thmb;
  
      if(thumbnail.src)
      {
          if(thumbnail.onerror)
          {
              thumbnail.src = "http://blog.lefigaro.fr/bd/img-sanctuaire.png";
          }
      }
      else
      {
          thumbnail.style.display = "none";
      }
  </code></pre>
  
  <p>Bu it doesn't work, when I empty the src code in HTML, the border of the image still in the page. And if I write a wrong URL, we can't see the image set in the JavaScript.
  Here is the JSFiddle to experiment it.
  <a href="http://jsfiddle.net/gUb8X/" rel="nofollow">http://jsfiddle.net/gUb8X/</a></p>
  
  <p>I'm a beginner in JavaScript.
  Thank you !</p>