title: JavaScript Image().width returns 0
body: <p>I need to get width and height of images with display:none and I'm getting both width and height 0.
  here's my code:</p>
  
  <pre><code>for (i = 0; i &lt;= slideCount; ++i) {
              imgPath = slideshow.eq(i).attr("src");
              imgEle = new Image();
              imgEle.src = imgPath;
  
              imgEle.addEventListener("load", function () {
                  imgSize = [imgEle.width, imgEle.height];
                  if ((imgSize[0]/imgSize[1]) &gt; (boxSize[0]/boxSize[1])) {
                      slideshow.eq(i).css("height", "100%");
                  }
                  else {
                      slideshow.eq(i).css("width", "100%");
                  }
              });
          }
  </code></pre>
  
  <p>I tried <code>onload = funcion() {}</code> approach as well as not checking if image is loaded, yet still I'm getting width and height as 0. What's more when i launched console on Chrome and referred to those fields I got proper values.</p>