How do I get actual image width and height using jQuery?

You can retrieve the original dimensions of an image by using the naturalWidth and naturalHeight properties of the dom object.

Eg.

var image = document.getElementById('someImage');

var originalWidth = image.naturalWidth; 
var originalHeight = image.naturalHeight;

With jQuery it would look like:

var image = $('#someImage');

var originalWidth = image[0].naturalWidth; 
var originalHeight = image[0].naturalHeight;

Leave a Comment