Skip to main content

Bug Tracker

Side navigation

#1818 closed bug (fixed)

Opened October 18, 2007 02:19PM UTC

Closed December 11, 2007 04:46AM UTC

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:
Blocked by: Blocking:
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 (1)
  • jQueryBug.html (4.2 KB) - added by BryceLohr October 18, 2007 02:20PM UTC.

    Demonstrates incorrect width() results

Change History (1)

Changed December 11, 2007 04:46AM UTC by brandon comment:1

resolution: → fixed
status: newclosed

Fixed in Rev [4100].