Hi Chris,

Someone wrote an ancestorsTo() plugin a while back. There was some talk about changing its name to parentsUntil() and including it with nextUntil() in a single plugin. Not sure who wrote the plugin originally, but Dave Methvin refers to it here:

Would this be a candidate for addition to the core possibly?


The ancestorsTo looks like it's an up-the-tree analog of the nextUntil
method for siblings that was discussed here a while back. I think the
general consensus on that was that there would be an extended navigation plugin rather than add all these to the core. Maybe they should be named
ancestorsUntil and siblingsUntil for better consistency?

Also, since this is a modifying plugin it should use pushStack() to allow the use of .end() to get back to the previous selected nodes. I think the
end result would be something like this, untested:

jQuery.fn.ancestorsUntil = function(match) {
         var a = [];
         jQuery(this[0]).ancestors().each(function() {
            a.push(this);
            return !jQuery(this).is(match);
         });
        return this.pushStack(a, arguments);
};

Hope that helps.


--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jan 15, 2007, at 9:09 PM, Chris Domigan wrote:

Hi there,

How would I select the first ancestor of a certain type? Eg if I want to select the first div that is found while searching up the DOM from an element.

Cheers,

Chris
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to