Skip to content

Commit 8533da9

Browse files
committed
Fixed an issue with :nth-child selectors embedded in :not() filters. Fixes jQuery bug jquery#4156.
1 parent a720bb3 commit 8533da9

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/selector.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ var Expr = Sizzle.selectors = {
422422
}
423423
return false;
424424
}
425-
} else if ( Expr.match.POS.test( match[0] ) ) {
425+
} else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
426426
return true;
427427
}
428428

@@ -519,6 +519,25 @@ var Expr = Sizzle.selectors = {
519519
}
520520
},
521521
filter: {
522+
PSEUDO: function(elem, match, i, array){
523+
var name = match[1], filter = Expr.filters[ name ];
524+
525+
if ( filter ) {
526+
return filter( elem, i, match, array );
527+
} else if ( name === "contains" ) {
528+
return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
529+
} else if ( name === "not" ) {
530+
var not = match[3];
531+
532+
for ( var i = 0, l = not.length; i < l; i++ ) {
533+
if ( not[i] === elem ) {
534+
return false;
535+
}
536+
}
537+
538+
return true;
539+
}
540+
},
522541
CHILD: function(elem, match){
523542
var type = match[1], node = elem;
524543
switch (type) {
@@ -562,25 +581,6 @@ var Expr = Sizzle.selectors = {
562581
}
563582
}
564583
},
565-
PSEUDO: function(elem, match, i, array){
566-
var name = match[1], filter = Expr.filters[ name ];
567-
568-
if ( filter ) {
569-
return filter( elem, i, match, array );
570-
} else if ( name === "contains" ) {
571-
return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
572-
} else if ( name === "not" ) {
573-
var not = match[3];
574-
575-
for ( var i = 0, l = not.length; i < l; i++ ) {
576-
if ( not[i] === elem ) {
577-
return false;
578-
}
579-
}
580-
581-
return true;
582-
}
583-
},
584584
ID: function(elem, match){
585585
return elem.nodeType === 1 && elem.getAttribute("id") === match;
586586
},

test/unit/selector.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ test("multiple", function() {
180180
});
181181

182182
test("child and adjacent", function() {
183-
expect(48);
183+
expect(49);
184184
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
185185
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
186186
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@@ -211,6 +211,7 @@ test("child and adjacent", function() {
211211

212212
t( "First Child", "p:first-child", ["firstp","sndp"] );
213213
t( "Nth Child", "p:nth-child(1)", ["firstp","sndp"] );
214+
t( "Not Nth Child", "p:not(:nth-child(1))", ["ap","en","sap","first"] );
214215

215216
// Verify that the child position isn't being cached improperly
216217
jQuery("p:first-child").after("<div></div>");

0 commit comments

Comments
 (0)