Ticket #11759 (closed bug: invalid)
Chrome 18 - $("img").width() methods always return 0
| Reported by: | sverrimo@… | Owned by: | sverrimo@… |
|---|---|---|---|
| Priority: | low | Milestone: | None |
| Component: | unfiled | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Hey,
I am writing a small plugin that emulates tooltips. When I used the plugin on an image I ran into this problem. I am quite sure it is a bug of some kind.
The methods width(), innerWidth() and outerWidth() all return 0 (zero) in Chrome 18. Using the methods on something else (such as a simple span) does work, however.
I ran the code in IE, FF and Opera and it works fine there. I get no errors or warnings anywhere.
This code reproduces the problem for me:
<span id="span">Some text to widen span</span>
<img src="image.jpg" id="image">
<script>
$(function(){
console.log("Span width: " + $("#span").width()); // 150
console.log("Span innerWidth: " + $("#span").innerWidth()); // 150
console.log("Span outerWidth: " + $("#span").outerWidth()); // 150
console.log("Image width: " + $("#image").width()); // 0
console.log("Image innerWidth: " + $("#image").innerWidth()); // 0
console.log("Image outerWidth: " + $("#image").outerWidth()); // 0
});
</script>
Can anyone verify that this is indeed a bug?
jQuery 1.7.2 in Chrome 18.
Thanks!
Change History
comment:2 Changed 12 months ago by sindresorhus
- Owner set to sverrimo@…
- Priority changed from undecided to low
- Status changed from new to pending
Since you can't reproduce it with jsFiddle, can you please add a runnable and simplified testcase on a webserver or as a downloadable zip?
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Okay, I saw the notice about using jsFiddle. Here it is:
http://jsfiddle.net/c3rGv/
It appears to work on jsFiddle, which makes me believe that it must have something to do with offline images. The width() methods seems to work on online images but not local ones.
... Which probably means that it is a bug with the Chrome browser and not jQuery.