Skip to content

Commit e25c4a1

Browse files
committed
Change the behavior of how :visible and :hidden work. :hidden is when an element is display none, a parent element is display none, or the element has a width of 0. :visible is when the element is not display none and all of its ancesotrs are not display none and its width is larger than 0. Fixes jQuery bugs jquery#1349, jquery#3265, and jquery#3895.
1 parent 5586fed commit e25c4a1

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/selector.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,15 +937,11 @@ jQuery.expr = Sizzle.selectors;
937937
jQuery.expr[":"] = jQuery.expr.filters;
938938

939939
Sizzle.selectors.filters.hidden = function(elem){
940-
return "hidden" === elem.type ||
941-
jQuery.css(elem, "display") === "none" ||
942-
jQuery.css(elem, "visibility") === "hidden";
940+
return elem.offsetWidth === 0;
943941
};
944942

945943
Sizzle.selectors.filters.visible = function(elem){
946-
return "hidden" !== elem.type &&
947-
jQuery.css(elem, "display") !== "none" &&
948-
jQuery.css(elem, "visibility") !== "hidden";
944+
return elem.offsetWidth > 0;
949945
};
950946

951947
Sizzle.selectors.filters.animated = function(elem){

test/unit/selector.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ test("attributes", function() {
308308
});
309309

310310
test("pseudo (:) selectors", function() {
311-
expect(67);
311+
expect(70);
312312
t( "First Child", "p:first-child", ["firstp","sndp"] );
313313
t( "Last Child", "p:last-child", ["sap"] );
314314
t( "Only Child", "a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
@@ -354,8 +354,11 @@ test("pseudo (:) selectors", function() {
354354
t( "Position Greater Than", "p:gt(0)", ["ap","sndp","en","sap","first"] );
355355
t( "Position Less Than", "p:lt(3)", ["firstp","ap","sndp"] );
356356
t( "Is A Parent", "p:parent", ["firstp","ap","sndp","en","sap","first"] );
357-
t( "Is Visible", "#form input:visible", ["text1","text2","radio1","radio2","check1","check2","name"] );
358-
t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
357+
t( "Is Visible", "#form input:visible", [] );
358+
t( "Is Visible", "div:visible:not(.testrunner-toolbar)", ["nothiddendiv", "nothiddendivchild"] );
359+
t( "Is Hidden", "#form input:hidden", ["text1","text2","radio1","radio2","check1","check2","hidden1","hidden2","name"] );
360+
t( "Is Hidden", "#main:hidden", ["main"] );
361+
t( "Is Hidden", "#dl:hidden", ["dl"] );
359362

360363
t( "Check position filtering", "div#nothiddendiv:eq(0)", ["nothiddendiv"] );
361364
t( "Check position filtering", "div#nothiddendiv:last", ["nothiddendiv"] );

0 commit comments

Comments
 (0)