Bug Tracker

Ticket #1818 (closed bug: fixed)

Opened 14 months ago

Last modified 12 months ago

width() returns incorrect value for hidden fixed/absolute position elements without a width

Reported by: BryceLohr Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: width css absolute positioning Cc:
Needs: Review

Description

jQuery's width() method returns an incorrect value when used on an invisible element with absolute or fixed positioning. However, this is only the case when the invisible element does not have an explicitly assigned width. This can be traced to the css() method: in its "width" case for invisible elements, it clones the node and sets the padding/border widths to zero to measure the element. The problem is that it also explicitly sets the "left" and "right" edge positions, which will implicitly change the element's width when it has no explicit width. That code appears to be intended to position the element at the origin point of the page, but due to a simple oversight actually ends up changing the element size. This behaviour is consistently incorrect on Firefox 2, IE 7, and Opera 9 (all on Windows; I don't have access to a Mac).

The work-around, is of course, to display the element before trying to get its size. However, you shouldn't have to do this, and usually you want to position the element before displaying it. Changing the positioning to something else is no good, since that completely changes how the browser sizes the element.

I've attached an HTML file showing the bug. This bug may be related to, or the cause of, bugs #1347 and #984.

Attachments

jQueryBug.html (4.2 KB) - added by BryceLohr 14 months ago.
Demonstrates incorrect width() results

Change History

Changed 14 months ago by BryceLohr

Demonstrates incorrect width() results

Changed 12 months ago by brandon

  • status changed from new to closed
  • resolution set to fixed

Fixed in Rev [4100].

Note: See TracTickets for help on using tickets.