From: jeresig Date: Fri, 22 Oct 2010 06:16:14 +0000 (-0400) Subject: Make sure that the correct height/width of the elements is retreived. Fixes #7225. X-Git-Tag: 1.4.4rc1~9 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7e02cee5ff8b5e9117366d7b43af7b5794f0f258;p=jquery.git Make sure that the correct height/width of the elements is retreived. Fixes #7225. --- diff --git a/src/css.js b/src/css.js index f2165f904..88c4ffa05 100644 --- a/src/css.js +++ b/src/css.js @@ -169,11 +169,23 @@ jQuery.each(["height", "width"], function( i, name ) { }); } - if ( val < 0 || val === 0 && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) { + if ( val < 0 ) { return elem.style[ name ] || "0px"; } - return val + "px"; + if ( val === 0 ) { + val = curCSS( elem, name, name ); + + if ( val != null ) { + return val; + } + } + + if ( val < 0 || val == null ) { + return elem.style[ name ]; + } + + return typeof val === "string" ? val : val + "px"; } }, diff --git a/test/unit/css.js b/test/unit/css.js index 8f24e2e34..2c2e9ed21 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1,7 +1,7 @@ module("css"); test("css(String|Hash)", function() { - expect(42); + expect(41); equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"'); @@ -13,21 +13,19 @@ test("css(String|Hash)", function() { var div = jQuery( "
" ); - equals( div.css("width"), "0px", "Width on disconnected node." ); - equals( div.css("height"), "0px", "Height on disconnected node." ); + equals( div.css("width") || "auto", "auto", "Width on disconnected node." ); + equals( div.css("height") || "auto", "auto", "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( "