You need to run the code when loading the image, the following code should work:
$(window).load( function() { $('.picture a img').load( function() { $(this).height(280); if ($(this).width() > $(this).height()) { alert("yes"); } else { alert("no"); } }); });
note that each DOM element that has some web resource associated with (window, img, iframe) responds to a .load () event.
Mo valipour
source share