Bug Tracker

Modify

Ticket #11759 (closed bug: invalid)

Opened 12 months ago

Last modified 12 months ago

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:1 Changed 12 months 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 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?

comment:3 Changed 12 months ago by sverrimo@…

  • Status changed from pending to new

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 12 months ago by mikesherov

  • Status changed from new to closed
  • Resolution set to invalid

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.