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