nice! of course, managing another mini-plugin isn't really much more convenient (for me, at least) than just reusing the two lines i posted when i need this. i think Jack (and myself, once he mentioned it) was suggesting that jQuery already supported this idiom, not that he lacked a solution. :)
On Fri, Jul 31, 2009 at 9:07 AM, Andrea Giammarchi<andrea.giammar...@gmail.com> wrote: > Add this instantly after jQuery inclusion if you need it, and problem > solved, isn't it? > > $ = jQuery = (function($){ > function jQuery(selector, context){ > var r = $.apply(this, arguments); > return context && $(context).is(selector) ? r.andSelf() : r; > }; > jQuery.prototype = $.prototype; > $.extend(jQuery, $); > return jQuery; > })(jQuery); > > Regards > > > On Fri, Jul 31, 2009 at 4:55 PM, Nathan Bubna <nbu...@gmail.com> wrote: >> >> 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 -~----------~----~----~----~------~----~------~--~---