jquery get image size

image, jquery, size

Solution

I asked the same question recently and got a good answer: A new image element is created but not attached to the DOM. Its height and width are the original dimensions of the image.

Edit: I edited the answer to my question now as promised in the comments. Detection of the image size is now bound to the `onload` event of the image to guarantee reliable results.

Problem

I am creating a photo gallery using jquery. I am taking and resizing the images on load to create thumbnails. I want to get the original value of the image's size so that later on I can take it back to its original size. Anyone know how to do this? I have the following code: ``` obj.find("img").each(function(){ }); ``` This loops through all the images within the container div. I then tried to do: ``` $(this).width(); //didnt work this.width; //didnt work ``` any ideas?

Original source

Related problems