Definitely worth mentioning... very handy...

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of mkmanning
Sent: Sunday, March 01, 2009 8:23 PM
To: jQuery (English)
Subject: [jQuery] Re: How to find a parent


It's probably worth mentioning that jQuery 1.3 also has a new 'closest'
method that would achieve this:

$('#cancel').closest('div.popup')

On Mar 1, 2:57 am, "Rick Faircloth" <r...@whitestonemedia.com> wrote:
> Glad we could help!  I was close anyway! :o)
>
> Rick
>
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] 
> On
>
> Behalf Of riotbrrd
> Sent: Sunday, March 01, 2009 12:58 AM
> To: jQuery (English)
> Subject: [jQuery] Re: How to find a parent
>
> You guys rock! thanks.
>
> So, .parents works, .parent does not. I think the reason is
> this: .parent only finds the single parent immediately up the tree, 
> but the div I'm looking for is actually several nodes up. The node 
> that .parent finds is not a div.popup, so I get no object back.
>
> Thanks again!
> -Kim
>
> On Feb 28, 9:33 pm, "Rick Faircloth" <r...@whitestonemedia.com> wrote:
> > Hmmm...after looking at the docs, it would seem "parent" would be 
> > more appropriate since Kim is looking for the first parent of the 
> > link '#cancel'.
>
> > Why would you think it should be "parents" which would return more 
> > than the first parent.
>
> > Am I misunderstanding something?
>
> > Rick
>
> > -----Original Message-----
> > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com]
> > On
>
> > Behalf Of Rick Faircloth
> > Sent: Sunday, March 01, 2009 12:26 AM
> > To: jquery-en@googlegroups.com
> > Subject: [jQuery] Re: How to find a parent
>
> > Thanks for the tip!
>
> > Rick
>
> > -----Original Message-----
> > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com]
> > On Behalf Of mkmanning
> > Sent: Sunday, March 01, 2009 12:18 AM
> > To: jQuery (English)
> > Subject: [jQuery] Re: How to find a parent
>
> > It should be .parents
>
> >   $(this).parents('div.popup:first')
>
> > On Feb 28, 9:05 pm, "Rick Faircloth" <r...@whitestonemedia.com> wrote:
> > > Assuming that the cancel link has an id of 'cancel':
>
> > > How about:
>
> > > $(document).ready(function() {
>
> > >      $('#cancel').click(function() {
> > >                 $(this).parent('div.popup:first')
> > >      });
>
> > > });
>
> > > Not sure what you want to do with the parent div when you locate it...
>
> > > untested, buy may work...
>
> > > hth,
>
> > > Rick
>
> > > -----Original Message-----
> > > From: jquery-en@googlegroups.com 
> > > [mailto:jquery...@googlegroups.com]
> > > On
>
> > > Behalf Of riotbrrd
> > > Sent: Saturday, February 28, 2009 11:47 PM
> > > To: jQuery (English)
> > > Subject: [jQuery] How to find a parent
>
> > > I have a bunch of Divs with class ".popup". Each div is different 
> > > in what it contains; some are simple, some are pretty complex, 
> > > containing tables, other divs, etc..
>
> > > If I have a link, for example,"Cancel", within that Div, and the 
> > > only thing that I know about Cancel is that 1) it has a parent 
> > > div.popup somewhere up the tree (no idea how many levels), and 2) 
> > > if I go backwards up the tree from Cancel, the first div.popup I 
> > > encounter will be the right one, how can I go about finding the 
> > > right parent div.popup? I'd like to just attach a handler that 
> > > starts
> with "this"
> > > (meaning the Cancel link) and finds the correct div.popup up the tree.
>
> > > Hope this is question is clear. Thanks!
> > > -Kim- Hide quoted text -
>
> > - Show quoted text -

Reply via email to