Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / December 2006



Tip: Looking for answers? Try searching our database.

JQuery and ancestors

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yanick - 30 Dec 2006 17:39 GMT
Is it possible, with JQuery to get only one specific element ancestor ?
For example :

<div>
 <ul id="tree">
   <li><a>Item 1</a>
     <ul id="subTree">
       <li><a>Item 1.1</a></li>
     </ul>
   </li>
 </ul>
</div>

$('ul li a').click( function() {

  // get first UL here

} );

That is, if I click on "item 1" I want to get the "tree" DOMelement,
and when I click on "item 1.1" I want to get the "subTree" DOMelement
only. How can this be achieved ?
Yanick - 30 Dec 2006 17:45 GMT
> Is it possible, with JQuery to get only one specific element ancestor ?
> For example :
[quoted text clipped - 18 lines]
> and when I click on "item 1.1" I want to get the "subTree" DOMelement
> only. How can this be achieved ?

I should specify : I would rather like to avoid
$(this).parent().parent() or similar syntax, and would prefer use
something like $(this).ancestors('ul')[0] or something.
Peter Michaux - 30 Dec 2006 17:53 GMT
> Is it possible, with JQuery to get only one specific element ancestor ?

If no one here has an answer you will probably have better luck with
the jquery mailing list

<URL: http://jquery.com/discuss/>

Peter
Kevin Scholl - 31 Dec 2006 01:25 GMT
>> Is it possible, with JQuery to get only one specific element ancestor ?
>
> If no one here has an answer you will probably have better luck with
> the jquery mailing list
>
> <URL: http://jquery.com/discuss/>

I would suggest that the luck would be better there in any circumstance.
The JQuery community is extremely helpful, and generally very quick to
respond.

Web-based access to the JQuery list (via Nabble):

http://www.nabble.com/JQuery-f15494.html

Signature

*** Remove the DELETE from my address to reply ***

======================================================
 Kevin Scholl                http://www.ksscholl.com/
 kscholl@comcast.DELETE.net
------------------------------------------------------
 Information Architecture, Web Design and Development
------------------------------------------------------
 We are the music makers, and we are the dreamers of
 the dreams...
======================================================

Yanick - 31 Dec 2006 19:32 GMT
> >> Is it possible, with JQuery to get only one specific element ancestor ?
> >
[quoted text clipped - 12 lines]
>
> --

Thanks to you both. I found this :

$(this).parents('ul:first')

I guess it's the most simple way to get this.

Cheers.

> *** Remove the DELETE from my address to reply ***
>
[quoted text clipped - 7 lines]
>   the dreams...
> ======================================================
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.