Skip to main content

Bug Tracker

Side navigation

#11759 closed bug (invalid)

Opened May 13, 2012 12:55AM UTC

Closed May 16, 2012 01:51AM UTC

Chrome 18 - $("img").width() methods always return 0

Reported by: sverrimo@gmail.com Owned by: sverrimo@gmail.com
Priority: low Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
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!

Attachments (0)
Change History (4)

Changed May 13, 2012 01:13AM UTC by sverrimo@gmail.com comment:1

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.

Changed May 15, 2012 10:01AM UTC by sindresorhus comment:2

owner: → sverrimo@gmail.com
priority: undecidedlow
status: newpending

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?

Changed May 16, 2012 01:38AM UTC by sverrimo@gmail.com comment:3

status: pendingnew

Okay, I cannot seem to reproduce this problem myself, so it must have been a fluke.

My apologies for taking up your time unnecessarily.

Changed May 16, 2012 01:51AM UTC by mikesherov comment:4

resolution: → invalid
status: newclosed

No worries! Thanks for taking the time to file a report.