Edit Updated to use one() instead of deprecated load()
load()
is aysnchronous, so will not set the value of imgHeight
before your call to $('body').prepend('<p>Image Height: ' + imgHeight + '</p>');
. Also the load()
event handler function is deprecated as of jQuery 1.8.
It would be best to attach a delegated load listener to the body for any images with the .select
class. In the callback of that event handler, you can detect the image height.
$(document).ready(function() {
$('body').one('load', 'img.select', function(e) {
var imgHeight = $('img.select').outerHeight();
$('body').prepend('<p>Image Height: ' + imgHeight + '</p>');
});
$('body').prepend('<img src="http://farm9.staticflickr.com/8266/8653931785_4a8d43164f.jpg" class="select" />');
});