On Thu, Jul 30, 2009 at 8:22 PM, Karl Swedberg<k...@englishrules.com> wrote:
> Hi Jack,
> One way you could do it is to use the .andSelf() method:
> $(context).find('selector').andSelf();
> http://docs.jquery.com/Traversing/andSelf

that's fine if you already know the self matches the selector.  but if
you're not sure, it's more like:

var $found = $(context).find('selector');
if ($(context).is('selector')) $found = $found.andSelf();

i have a few of places where i have to do this and would also be happy
to see a feature that simplified it.

> --Karl
> ____________
> Karl Swedberg
> www.englishrules.com
> www.learningjquery.com
>
>
>
> On Jul 30, 2009, at 5:10 PM, Jack Bates wrote:
>
> i wish there were a convenient way to apply a selector to an element
> and its descendants
>
> the following works, except that it excludes the context element,
> whether it matches the selector or not,
>
> $('selector', context)
>
> the following applies the selector to the context element and its
> descendants, but additionally applies it to the context element's
> siblings and their descendants,
>
> $('selector', context.parentNode)
>
> may i file a ticket, for applying the selector to the context element,
> as well as its descendants?
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to