Thanks for the tip! Here's the updated code... (This is also available at
http://jdsharp.us/code/jQuery/)

jQuery.fn.ancestorsTo = function(match) {
       var j = jQuery();
       var b = false;
       jQuery(this[0]).ancestors().each(function() {
           if (b == false) {
               j.add(this);
               b = jQuery(this).is(match);
           }
       });
       return j;
};

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

Cheers,
-js


On 12/13/06, Matt Stith <[EMAIL PROTECTED]> wrote:

plugin devs should remember: Never use $ inside your plugins. Always use
'jQuery'. The reason is that '$' can be changed by the user for support with
other libraries.

On 12/13/06, Jonathan Sharp <[EMAIL PROTECTED]> wrote:

>  I wrote a method that will provide a list of ancestors for any number
> of generations until an ancestor matches the expression. Example:
>
> BODY
>   DIV
>     UL.myClass
>       LI
>         UL
>           LI #myId
>
> $('#myId').ancestors()
> returns [UL, LI, UL.myClass, DIV, BODY]
>
> $('#myId').ancestors("UL.myClass")
> returns [UL.myClass]
>
> Returns all elements up to and including the match expression
> $('#myId').ancestorsTo("UL.myClass")
> returns [UL, LI, UL.myClass]
>
> Code:
> jQuery.fn.ancestorsTo = function(match) {
>         var j = $();
>
>         var b = false;
>         $(this[0]).ancestors().each(function() {
>             if (b == false) {
>                 j.add(this);
>
>                 if ($(this).is(match)) {
>                     b = true;
>                 }
>             }
>         });
>
>         return j;
>     };
>
>
> Cheers,
> -js
>
> _______________________________________________
> jQuery mailing list
> [email protected]<https://mail.google.com/mail?view=cm&tf=0&[EMAIL 
PROTECTED]>
> http://jquery.com/discuss/
>
>
>

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



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

Reply via email to