Skip to content

Commit c43066c

Browse files
committed
CSS: disconnected elements should be hidden
Fixes jquerygh-3043
1 parent 59003ae commit c43066c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/css/hiddenVisibleSelectors.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
define( [
22
"../core",
3+
"../var/document",
34
"./support",
45
"../selector",
56
"../css"
6-
], function( jQuery, support ) {
7+
], function( jQuery, document, support ) {
78

89
function getDisplay( elem ) {
910
return elem.style && elem.style.display || jQuery.css( elem, "display" );
1011
}
1112

1213
function filterHidden( elem ) {
14+
15+
// Disconnected elements are considered hidden
16+
if ( !jQuery.contains( elem.ownerDocument || document, elem ) ) {
17+
return true;
18+
}
1319
while ( elem && elem.nodeType === 1 ) {
1420
if ( getDisplay( elem ) === "none" || elem.type === "hidden" ) {
1521
return true;

test/unit/css.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ QUnit.test( "css opacity consistency across browsers (#12685)", function( assert
10591059
} );
10601060

10611061
QUnit.test( ":visible/:hidden selectors", function( assert ) {
1062-
assert.expect( 17 );
1062+
assert.expect( 19 );
10631063

10641064
var $div, $table, $a;
10651065

@@ -1100,6 +1100,9 @@ QUnit.test( ":visible/:hidden selectors", function( assert ) {
11001100

11011101
$a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
11021102
assert.ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
1103+
1104+
assert.ok( !jQuery( "<div>Test</div>" ).is( ":visible" ), "Disconnected element is not visible" );
1105+
assert.ok( !jQuery( "<div><div>Test</div></div>" ).find("div").is( ":visible" ), "Disconnected element child is not visible" );
11031106
} );
11041107

11051108
QUnit.test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function( assert ) {

0 commit comments

Comments
 (0)