Bug Tracker

Opened 7 years ago

Closed 7 years ago

#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:
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!

Change History (4)

comment:1 Changed 7 years ago by sverrimo@…

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.

comment:2 Changed 7 years ago by sindresorhus

Owner: set to sverrimo@…
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?

comment:3 Changed 7 years ago by sverrimo@…

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.

comment:4 Changed 7 years ago by mikesherov

Resolution: invalid
Status: newclosed

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

Note: See TracTickets for help on using tickets.