How to add dimensions to dynamic img elements
- by Mohammad
I use a Json call to get a list of image addresses, then I add them individually to a div like this.
<div id="container">
<img src="A.jpg" alt="" />
<img src="B.jpg" alt="" />
...
</div>
Unfortunately the image dimension is not part of the Json information but I do need them for later JQuery DOM interactivity. Do any of you JQuery geniuses know of a code that would flawlessly add the width and height to the individual image elements in the container after they load?
I was thinking maybe the code could wait for the images to have a width bigger than 5px then add the new width and height to the element. But I wouldn't know how to go about that and make it work stably.
Thank you so much!