diff options
author | Rick Waldron <waldron.rick@gmail.com> | 2012-05-07 16:38:55 -0400 |
---|---|---|
committer | Rick Waldron <waldron.rick@gmail.com> | 2012-05-07 16:38:55 -0400 |
commit | df254d47e43e6e1652b20a3b338b26f634cd2b2a (patch) | |
tree | d2e4bada0a56373b06f4508fe5d750bc5b59070d /src/traversing.js | |
parent | 2af3642cd5f968d64c40b83250e00e077b48c086 (diff) | |
download | jquery-df254d47e43e6e1652b20a3b338b26f634cd2b2a.tar.gz jquery-df254d47e43e6e1652b20a3b338b26f634cd2b2a.zip |
Additional reduction per @Raynos suggestion. Thanks!
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
Diffstat (limited to 'src/traversing.js')
-rw-r--r-- | src/traversing.js | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/traversing.js b/src/traversing.js index d2a8cd1b4..027996e27 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -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" ); |