Skip to main content

Bug Tracker

Side navigation

#12313 closed bug (fixed)

Opened August 15, 2012 09:04PM UTC

Closed August 28, 2012 01:00PM UTC

.height() and .width() no longer fall back to CSS if offsetWidth is undefined.

Reported by: Owned by: mikesherov
Priority: blocker Milestone: 1.8.1
Component: css Version: 1.8.0
Keywords: Cc: mikesherov
Blocked by: Blocking:

offsetWidth and offsetHeight are undefined for SVG elements in Firefox and IE 9. jQuery used to fall back to computed, then uncomputed CSS in this case, but that no longer happens after the following commit:

In "getWidthOrHeight":

// Start with offset property
var val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
  i = name === "width" ? 1 : 0,
  len = 4;

if ( val > 0 ) {

// Fall back to computed then uncomputed css if necessary
  val = curCSS( elem, name );

"val > 0" failed if offsetWidth or offsetHeight were undefined, so fallback would always occur.

In 5376a809 the condition was changed to the following:

if ( val <= 0 ) {
    // Fall back to computed then uncomputed css if necessary
    val = curCSS( elem, name );

"undefined" will never be <= 0. I think it's possible the former conditional logic caught the "undefined" case by accident. If not, the intent of the conditional logic was not clear if it was supposed to handle "undefined" (but may have saved bytes).

Test case:

This will show NaNpx for height and width in Firefox and IE9, 200 in Chrome. The assertion in the console will also fail.

It looks like a bug for offsetWidth/Height being undefined on SVG elements in Firefox has been filed:

Attachments (0)
Change History (4)

Changed August 21, 2012 12:39AM UTC by dmethvin comment:1

cc: → mikesherov
component: unfiledcss
milestone: None1.8.1
priority: undecidedblocker
status: newopen

Mike, looks like it should be fixable if we tweak the conditional?

Changed August 21, 2012 12:58AM UTC by mikesherov comment:2

owner: → mikesherov
status: openassigned

TIL that:

undefined < 0 // false
undefined > 0 // false
undefined == 0 // false
!undefined // true

PR to come shortly.

Changed August 25, 2012 03:32PM UTC by mikesherov comment:3

Changed August 28, 2012 01:00PM UTC by Mike Sherov comment:4

resolution: → fixed
status: assignedclosed

Fix #12313, .height()/.width() just use CSS if no offsetWidth. Close gh-909.

Changeset: c078b83b3fea891e0c228a9f2d101481678b4c9d