Get Image Original Height and Width using jQuery

Use the following code to find the natural / actual height and width of an html image.

var image = new Image();
image.src = $j("img").attr("src");
alert(
'width: ' + image.naturalWidth + ' and height: ' + image.naturalHeight);

This approach doesn't work in IE 8 and below versions, because it doesn't support 'naturalWidth' and 'naturalHeight' properties. To achieve the same use this code

image.onload = function() {
alert(
'width: ' + this.width + ' and height: ' + this.height);
};