title: Javascript display dynamic changing image
body: <p>I want to refresh an image every 1 second. This picture is dynamically generated by my webcam, but this script sometimes display broken images when browser didnt yet load a picture before display. How to detect when picture is loaded and then change the diplay picture? 
  I have a code like this:</p>
  
  <pre><code>    &lt;img id="image" src="webcam.jpg"&gt;
  
  
  &lt;script&gt;
  setInterval(function() {
      var myImageElement = document.getElementById('image');
      myImageElement.src = 'webcam.jpg?rand=' + Math.random();
  }, 1000);
  &lt;/script&gt;
  </code></pre>