aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2009-02-16 17:58:33 +0000
committerJohn Resig <jeresig@gmail.com>2009-02-16 17:58:33 +0000
commit8533da939d933561aa6c516db4e544dba076a988 (patch)
tree645b6ed8859a8a82109ea689292b0bf0ff89ffc2
parenta720bb31ab32c5629607a471e4674fd11e05b97c (diff)
downloadjquery-8533da939d933561aa6c516db4e544dba076a988.tar.gz
jquery-8533da939d933561aa6c516db4e544dba076a988.zip
Fixed an issue with :nth-child selectors embedded in :not() filters. Fixes jQuery bug #4156.
-rw-r--r--src/selector.js40
-rw-r--r--test/unit/selector.js3
2 files changed, 22 insertions, 21 deletions
diff --git a/src/selector.js b/src/selector.js
index 69ea36cd9..505198b23 100644
--- a/src/selector.js
+++ b/src/selector.js
@@ -422,7 +422,7 @@ var Expr = Sizzle.selectors = {
}
return false;
}
- } else if ( Expr.match.POS.test( match[0] ) ) {
+ } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
return true;
}
@@ -519,6 +519,25 @@ var Expr = Sizzle.selectors = {
}
},
filter: {
+ PSEUDO: function(elem, match, i, array){
+ var name = match[1], filter = Expr.filters[ name ];
+
+ if ( filter ) {
+ return filter( elem, i, match, array );
+ } else if ( name === "contains" ) {
+ return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
+ } else if ( name === "not" ) {
+ var not = match[3];
+
+ for ( var i = 0, l = not.length; i < l; i++ ) {
+ if ( not[i] === elem ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ },
CHILD: function(elem, match){
var type = match[1], node = elem;
switch (type) {
@@ -562,25 +581,6 @@ var Expr = Sizzle.selectors = {
}
}
},
- PSEUDO: function(elem, match, i, array){
- var name = match[1], filter = Expr.filters[ name ];
-
- if ( filter ) {
- return filter( elem, i, match, array );
- } else if ( name === "contains" ) {
- return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
- } else if ( name === "not" ) {
- var not = match[3];
-
- for ( var i = 0, l = not.length; i < l; i++ ) {
- if ( not[i] === elem ) {
- return false;
- }
- }
-
- return true;
- }
- },
ID: function(elem, match){
return elem.nodeType === 1 && elem.getAttribute("id") === match;
},
diff --git a/test/unit/selector.js b/test/unit/selector.js
index 99cef579f..9f29bf6bf 100644
--- a/test/unit/selector.js
+++ b/test/unit/selector.js
@@ -180,7 +180,7 @@ test("multiple", function() {
});
test("child and adjacent", function() {
- expect(48);
+ expect(49);
t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
@@ -211,6 +211,7 @@ test("child and adjacent", function() {
t( "First Child", "p:first-child", ["firstp","sndp"] );
t( "Nth Child", "p:nth-child(1)", ["firstp","sndp"] );
+ t( "Not Nth Child", "p:not(:nth-child(1))", ["ap","en","sap","first"] );
// Verify that the child position isn't being cached improperly
jQuery("p:first-child").after("<div></div>");