Skip to content

Commit 7b9b98d

Browse files
committed
CSS: elements are hidden when either offsetWidth or offsetHeight is zero
- Note: this is a breaking change that has been delayed for several versions. Fixes #10406 Fixes #13132 Conflicts: src/css/hiddenVisibleSelectors.js
1 parent 181b451 commit 7b9b98d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/css/hiddenVisibleSelectors.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ define([
88
jQuery.expr.filters.hidden = function( elem ) {
99
// Support: Opera <= 12.12
1010
// Opera reports offsetWidths and offsetHeights less than zero on some elements
11-
return elem.offsetWidth <= 0 && elem.offsetHeight <= 0 ||
11+
// Use OR instead of AND as the element is not visible if either is true
12+
// See tickets #10406 and #13132
13+
return elem.offsetWidth <= 0 || elem.offsetHeight <= 0 ||
1214
(!support.reliableHiddenOffsets() &&
1315
((elem.style && elem.style.display) || jQuery.css( elem, "display" )) === "none");
1416
};

test/unit/css.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -944,29 +944,31 @@ test( "css opacity consistency across browsers (#12685)", function() {
944944
});
945945

946946
test( ":visible/:hidden selectors", function() {
947-
expect( 13 );
947+
expect( 16 );
948+
949+
var $newDiv, $br, $table;
948950

949951
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" );
950952
jQuery("#nothiddendiv").css({ display: "none" });
951953
ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" );
952-
jQuery("#nothiddendiv").css({"display": "block"});
954+
jQuery("#nothiddendiv").css({ "display": "block" });
953955
ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
954-
ok( jQuery(window).is(":visible") || true, "Calling is(':visible') on window does not throw an exception (#10267)");
955-
ok( jQuery(document).is(":visible") || true, "Calling is(':visible') on document does not throw an exception (#10267)");
956+
ok( !jQuery(window).is(":visible"), "Calling is(':visible') on window does not throw an exception (#10267).");
957+
ok( !jQuery(document).is(":visible"), "Calling is(':visible') on document does not throw an exception (#10267).");
956958

957959
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
958960
jQuery("#nothiddendiv").css("display", "none");
959961
ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
960962
jQuery("#nothiddendiv").css("display", "block");
961963
ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
962964

963-
// ok( !jQuery("#siblingspan").is(":visible"), "Span with no content not visible (#13132)" );
964-
// var $newDiv = jQuery("<div><span></span></div>").appendTo("#qunit-fixture");
965-
// equal( $newDiv.find(":visible").length, 0, "Span with no content not visible (#13132)" );
966-
// var $br = jQuery("<br/>").appendTo("#qunit-fixture");
967-
// ok( !$br.is(":visible"), "br element not visible (#10406)");
965+
ok( !jQuery("#siblingspan").is(":visible"), "Span with no content not visible (#13132)" );
966+
$newDiv = jQuery("<div><span></span></div>").appendTo("#qunit-fixture");
967+
equal( $newDiv.find(":visible").length, 0, "Span with no content not visible (#13132)" );
968+
$br = jQuery("<br/>").appendTo("#qunit-fixture");
969+
ok( !$br.is(":visible"), "br element not visible (#10406)");
968970

969-
var $table = jQuery("#table");
971+
$table = jQuery("#table");
970972
$table.html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
971973
equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements");
972974
$table.css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>");

0 commit comments

Comments
 (0)