How to add dimensions to dynamic img elements

Posted by Mohammad on Stack Overflow See other posts from Stack Overflow or by Mohammad
Published on 2010-04-23T08:17:35Z Indexed on 2010/04/23 8:23 UTC
Read the original article Hit count: 365

Filed under:
|
|
|

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!

© Stack Overflow or respective owner

Related posts about dom

Related posts about jQuery