title: Waiting for image to load in JavaScript
body: <p>I'm making an Ajax call which returns me some info including an image path.</p>
  
  <p>I prepare all this information in my HTML which will be displayed as a kind of popup. I just toggle the visibility of by popup div from hidden to visible.</p>
  
  <p>To set the position of my popup div, I have to calculate depending on the height of the image. So, I have to wait for the image to load to know its dimension before setting position and switching visibility to visible.</p>
  
  <p>I tried tricks with recursion, setTimeout, complete img property, while loop... without success.</p>
  
  <p>So, how can I do this? Maybe I should return dimensions in my Ajax call.</p>