As Josh mentioned, if the image has not fully loaded yet, jQuery won't know what the dimensions are yet. Try something like this to ensure you're only attempting to access it's dimensions after the image has been completely loaded.
As Josh mentioned, if the image has not fully loaded yet, jQuery won't know what the dimensions are yet. Try something like this to ensure you're only attempting to access it's dimensions after the image has been completely loaded: var img = new Image(); $(img). Load( function() { //-- you can determine the height before adding to the DOM alert("height: " + img.
Height); //-- or you can add it first... $('body'). Append(img); //-- and then check alert($('body img').height()); }). Error( function() { //-- this will fire if the URL is invalid, or some other loading error occurs alert("DANGER!... DANGER!..."); }); $(img).
Attr('src', "
").Preloading the image and setting up a callback function might be what you're looking for: // simple image preloader function getHeight(el,fn) { var img = new Image(); img. Onload = function() { fn(img. Height); }; img.
Src = el. Attr("src"); } $("img"). Each(function(){ getHeight($(this),function(h){ // what you need to do with the height value here alert(h); }); }).
My assumption is that this function is being called before the image is finished loading. Can you try putting a delay on the function to see if this is actually the case? If this is the case, you can cheat by using a timer before running the function.It is a bit more complicated to detect when an image has been loaded.
Have a look at this script for some ideas -- maybe it would work for you.
Or run the script in an body onload event, instead of the document ready event. It's not as precise, since the whole document has to load, but you can be sure the image has loaded (assuming it's an image in the code, not some AJAX loaded thing). – Frank DeRosa Nov 16 '09 at 18:39 2 @Frank, body onload gets called when the DOM is finished being created, it's not guaranteed that the assets within the DOM will have finished loading though (images included).
– JasonWyatt Nov 16 '09 at 18:46.
Try using an image pre-loader, here's one I wrote for an answer to another question.
A slightly ugly but effective fix that I used whas to use a backend language, in my case php, to get the height and setting it on the img before sending it to the browser. Its ugly, but simple and quick.
Just had the same issue: set the width and height beforehand via CSS or HTML.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.