From e4a38670b10b1ce776afff389bae34991e986180 Mon Sep 17 00:00:00 2001 From: jeresig Date: Fri, 22 Oct 2010 00:28:33 -0400 Subject: [PATCH] Make sure that height/width getters work on hidden inputs and disconnected elements. Fixes #7225. --- src/css.js | 4 ++++ test/unit/css.js | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/css.js b/src/css.js index 933d2b45e..f2165f904 100644 --- a/src/css.js +++ b/src/css.js @@ -169,6 +169,10 @@ jQuery.each(["height", "width"], function( i, name ) { }); } + if ( val < 0 || val === 0 && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { + return elem.style[ name ] || "0px"; + } + return val + "px"; } }, diff --git a/test/unit/css.js b/test/unit/css.js index 40959b146..ed8f919a8 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css"); test("css(String|Hash)", function() { - expect(34); + expect(42); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -11,6 +11,24 @@ test("css(String|Hash)", function() { jQuery('#nothiddendiv').css({display: 'block'}); ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible'); + var div = jQuery( "
" ); + + equals( div.css("width"), "0px", "Width on disconnected node." ); + equals( div.css("height"), "0px", "Height on disconnected node." ); + + div.css({ width: 4, height: 4 }); + + equals( div.css("width"), "4px", "Width on disconnected node." ); + equals( div.css("height"), "4px", "Height on disconnected node." ); + + var div2 = jQuery( "