Reputation: 382879
Suppose I have this image:
<img src="images/01.jpg" border="0" rel="shadow" />
Then with jQuery, I get its width using:
$('[rel="shadow"]').width();
Firefox and IE report correct dimensions of the image eg 140px while Chrome reports 0. How to solve this problem?
I don't want to set explicit width for images eg:
<img src="images/01.jpg" border="0" rel="shadow" width="140" />
So, how to get width in cross-browser way which is not defined in width
attribute of elements?
Upvotes: 1
Views: 3352
Reputation: 44832
$(window).load(
function() {
alert($('img').width());
}
);
This will work: Test case. Basically it will wait until images load before executing the code (when the ready function fires the document has been fully loaded but images haven't).
Upvotes: 8