jQuery Untils: nextUntil, prevUntil, parentsUntil
jQuery Untils provides three very simple, but very useful methods: nextUntil, prevUntil, and parentsUntil. These methods are based on their nextAll, prevAll, and parents counterparts, except that they allow you to stop when a certain selector is reached. Elements are returned in “traversal order”.
- Release v1.1
- Tested with jQuery 1.3.2 in Internet Explorer 6-8, Firefox 2-3.7, Safari 3-4, Chrome 4-5, Opera 9.6-10.1.
- Download Source, Minified (0.6kb)
- Follow the project on GitHub project page or report a bug!
- View Full Documentation
- View Unit Tests
- Examples: nextUntil, prevUntil, parentsUntil
Note that these methods take a less naïve approach than others bearing the same names, and are designed to actually return elements in traversal order, despite the element ordering flaws inherent in the jQuery 1.3.2 selector engine.
// Select all list items between the first and last. $("ul > :first").nextUntil( ":last" ); // The same elements, in the opposite order. $("ul > :last").prevUntil( ":first" ); // Select all "div" elements between .foo and .bar $(".foo").nextUntil( ".bar", "div" ); // Select all parent elements, excluding body and html. $(".foo").parentsUntil( "body" );
This is not rocket science. There really is no “advanced” usage!
This plugin is going to do exactly what you expect, except that it takes care of some general jQuery 1.3.2 selector issues when there are multiple elements in the initial selector. This might be an edge-case, but it exists nonetheless.
If you have any non-bug-related feedback or suggestions, please let me know below in the comments, and if you have any bug reports, please report them in the issues tracker, thanks!