JQuery 1.4's New 'Until' Methods Caught My Eye ... Introducing Element.GetUntil

By Ryan Florence, published 2010-01-15

Part of the issue Migrated Articles From Original Site Structure..

So I did what every good mootools developer would … extended MooTools to do the same. The names in jQuery are nextUntil, prevUntil, and parentsUntil. I decided to stick to mootools tradition and make my code more clear: getAllNextUntil, getAllPreviousUntil, and getParentsUntil.

Download it from the forge, fork it on github.

Luckily, this doesn’t ship with every copy of MooTools core, I can’t imagine very many practical uses–but like I said, it caught my eye, here’s a demo.

Here’s the source if you’re interested:

(function(){

    var walkUntil = function(element, walk, match, nocash){
        var el = element[walk];
        var elements = [];
        while (el){
            if (el.nodeType == 1){
                if (!match || Element.match(el, match)) {
                    break;
                } else {
                    elements.push(el);
                }
            }
            el = el[walk];
        }
        return new Elements(elements, {ddup: false, cash: !nocash});
    }

    Element.implement({
    
        getAllPreviousUntil: function(match, nocash){
            return walkUntil(this, 'previousSibling', match, nocash);
        },
    
        getAllNextUntil: function(match, nocash){
            return walkUntil(this, 'nextSibling', match, nocash);
        },
        
        getParentsUntil: function(match, nocash){
            return walkUntil(this, 'parentNode', match, nocash);
        }

    });

})();

MooTools in this article

Hi, I'm Ryan!

Location:
South Jordan, UT
Github:
rpflorence
Twitter:
ryanflorence
Freenode:
rpflo

About Me

I'm a front-end web developer from Salt Lake City, Utah and have been creating websites since the early 90's. I like making awesome user experiences and leaving behind maintainable code. I'm active in the JavaScript community writing plugins, contributing to popular JavaScript libraries, speaking at conferences & meet-ups, and writing about it on the web. I work as the JavaScript guy at Instructure.