[jQuery] parents() function

[jQuery] parents() function

I thought I'd try making a parents() function that would act as I
wanted, and suprisingly, it didn't seem to be too hard. Here's what I
have:
$.fn.parents = function(f) {
    jq = $("");
    for ( var i = 0; i < this.size(); i++ ) {
        el = this.get(i);
        c = el.parentNode;
        while (true) {
            jq.add(c);
            c = c.parentNode;
            if (c.parentNode == document)
                break;
        }
    }
    if (f) jq = jq.filter(f);
    return jq;
}
It should find all parents of all selected elements (although I've
only tested it with one element) and filter them using the f string
(I thought it would be nice as an option, instead of having to use
parents().filter(query)). It'll match up to and including body,
though I guess it might as well match all the way up to body.
Example:
http://bytetastic.com/bytecore2/jquery/test.htm
Audun Wilhelmsen
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/