]> source.dussan.org Git - jquery.git/commitdiff
Additional reduction per @Raynos suggestion. Thanks!
authorRick Waldron <waldron.rick@gmail.com>
Mon, 7 May 2012 20:38:55 +0000 (16:38 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Mon, 7 May 2012 20:38:55 +0000 (16:38 -0400)
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
src/traversing.js

index d2a8cd1b472d08c7084520ec9bc91c1be96a630d..027996e27a36d3607a03dfc7d8ae458e5fb4b9e2 100644 (file)
@@ -174,14 +174,9 @@ function isDisconnected( node ) {
        return !node || !node.parentNode || node.parentNode.nodeType === 11;
 }
 
-function nth( cur, dir ) {
-       var num = 0;
+function sibling( cur, dir ) {
+       while ( cur = cur[ dir ], cur.nodeType !== 1 ) {}
 
-       for ( ; cur; cur = cur[dir] ) {
-               if ( cur.nodeType === 1 && num++ === 1 ) {
-                       break;
-               }
-       }
        return cur;
 }
 
@@ -197,10 +192,10 @@ jQuery.each({
                return jQuery.dir( elem, "parentNode", until );
        },
        next: function( elem ) {
-               return nth( elem, "nextSibling" );
+               return sibling( elem, "nextSibling" );
        },
        prev: function( elem ) {
-               return nth( elem, "previousSibling" );
+               return sibling( elem, "previousSibling" );
        },
        nextAll: function( elem ) {
                return jQuery.dir( elem, "nextSibling" );