Waiting for image to load in JavaScript

I’m making an Ajax call which returns me some info including an image path. 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. 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. I tried tricks with recursion, setTimeout, complete img property, while loop… without success. So, how