Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created September 27, 2009 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboy/194959 to your computer and use it in GitHub Desktop.
Save cowboy/194959 to your computer and use it in GitHub Desktop.
// proposed 'until' extension to jQuery.dir to support 'nextUntil' and 'prevUntil'
// suggested by LaC_OS_X
jQuery.dir = function( elem, dir, until ){
var matched = [], cur = elem[dir];
while ( cur && cur != document ) {
if ( cur.nodeType == 1 )
matched.push( cur );
if ( until && jQuery( cur ).is( until ) )
return matched;
cur = cur[dir];
}
return matched;
};
jQuery.each({
nextUntil: function(elem,selector){return jQuery.dir(elem,"nextSibling",selector);},
prevUntil: function(elem,selector){return jQuery.dir(elem,"previousSibling",selector);}
}, function(name, fn){
jQuery.fn[ name ] = function( selector ) {
var ret = jQuery.map( this, function( elem ){ return fn( elem, selector ) } );
return this.pushStack( jQuery.unique( ret ), name, selector );
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment