title: JS/JQuery Retry Img Load After 1 Second
body: <p>I have a request calling up a bunch of images like so:</p>
  
  <pre><code>&lt;a href='www.domain1.com'&gt;&lt;img src='../image/img1.png' onerror='imgError(this);'/&gt;&lt;/a&gt;
  &lt;a href='www.domain2.com'&gt;&lt;img src='../image/img2.png' onerror='imgError(this);'/&gt;&lt;/a&gt;
  </code></pre>
  
  <p>The problem is when the call is made some of the images (~20%) are not ready yet. They need another second.</p>
  
  <p>So in js or jquery what I would like to do is on error get the images that failed, wait 1 second, then try to load those failed images again. If they fail on the 2nd try -- oh well, Im okay with that. But Im not doing this correctly... Should I not be calling a timeout inside of another method in js?</p>
  
  <pre><code>function imgError(image) {
      image.onerror = "";
      image.src = image;
  
      setTimeout(function () {
          return true;
      }, 1000);
  }
  </code></pre>