Skip to content
Permalink
Browse files

Make sure that height/width getters work on hidden inputs and disconn…

…ected elements. Fixes #7225.
  • Loading branch information...
jeresig committed Oct 22, 2010
1 parent 3df41db commit e4a38670b10b1ce776afff389bae34991e986180
Showing with 23 additions and 1 deletion.
  1. +4 −0 src/css.js
  2. +19 −1 test/unit/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";
}
},
@@ -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( "<div>" );

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( "<div style='display:none;'><input type='text'/><textarea/></div>").appendTo("body");

equals( div2.find("input").css("width"), "0px", "Width on hidden input." );
equals( div2.find("input").css("height"), "0px", "Height on hidden input." );

equals( div2.find("textarea").css("width"), "0px", "Width on hidden textarea." );
equals( div2.find("textarea").css("height"), "0px", "Height on hidden textarea." );

// handle negative numbers by ignoring #1599, #4216
jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 });

0 comments on commit e4a3867

Please sign in to comment.
You can’t perform that action at this time.