aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Resig <jeresig@gmail.com>2007-01-14 17:54:54 +0000
committerJohn Resig <jeresig@gmail.com>2007-01-14 17:54:54 +0000
commite50a2f6ca3a03501510228f940f48a0faa12127d (patch)
tree6ed1c6247c78f077d5423823a33288a814c821e1 /src
parent375499c1f3890b9f14c36fd50c80516ff5c7596e (diff)
downloadjquery-e50a2f6ca3a03501510228f940f48a0faa12127d.tar.gz
jquery-e50a2f6ca3a03501510228f940f48a0faa12127d.zip
Added a fix for :nth-child(even/odd).
Diffstat (limited to 'src')
-rw-r--r--src/selector/selector.js8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/selector/selector.js b/src/selector/selector.js
index 1e8d72996..8cff87fdd 100644
--- a/src/selector/selector.js
+++ b/src/selector/selector.js
@@ -14,7 +14,7 @@ jQuery.extend({
odd: "i%2",
// Child Checks
- "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling')==a",
+ "nth-child": "jQuery.nth(a.parentNode.firstChild,m[3],'nextSibling',a)==a",
"first-child": "jQuery.nth(a.parentNode.firstChild,1,'nextSibling')==a",
"last-child": "jQuery.nth(a.parentNode.lastChild,1,'previousSibling')==a",
"only-child": "jQuery.sibling(a.parentNode.firstChild).length==1",
@@ -409,13 +409,13 @@ jQuery.extend({
* @param String dir The direction to move in (pass in something like 'previousSibling' or 'nextSibling').
* @cat DOM/Traversing
*/
- nth: function(cur,result,dir){
+ nth: function(cur,result,dir,elem){
result = result || 1;
var num = 0;
for ( ; cur; cur = cur[dir] ) {
if ( cur.nodeType == 1 ) num++;
- if ( num == result || result == "even" && num % 2 == 0 && num > 1 ||
- result == "odd" && num % 2 == 1 ) return cur;
+ if ( num == result || result == "even" && num % 2 == 0 && num > 1 && cur == elem ||
+ result == "odd" && num % 2 == 1 && cur == elem ) return cur;
}
},