Bug Tracker

Opened 13 years ago

Closed 13 years ago

#1818 closed bug (fixed)

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:


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 13 years ago.
Demonstrates incorrect width() results

Download all attachments as: .zip

Change History (2)

Changed 13 years ago by BryceLohr

Attachment: jQueryBug.html added

Demonstrates incorrect width() results

comment:1 Changed 13 years ago by brandon

Resolution: fixed
Status: newclosed

Fixed in Rev [4100].

Note: See TracTickets for help on using tickets.