Bug Tracker

Opened 10 years ago

Closed 10 years ago

#11759 closed bug (invalid)

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

Reported by: [email protected] Owned by: [email protected]
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 10 years ago by [email protected]

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 10 years ago by sindresorhus

Owner: set to [email protected]
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 10 years ago by [email protected]

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 10 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.