473,626 Members | 3,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JQuery and ancestors

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 ?

Dec 30 '06 #1
4 8019

Yanick wrote:
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 ?
I should specify : I would rather like to avoid
$(this).parent( ).parent() or similar syntax, and would prefer use
something like $(this).ancesto rs('ul')[0] or something.

Dec 30 '06 #2
Yanick wrote:
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

Dec 30 '06 #3
Peter Michaux wrote:
Yanick wrote:
>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

--

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

=============== =============== =============== =========
Kevin Scholl http://www.ksscholl.com/
ks*****@comcast .DELETE.net
------------------------------------------------------
Information Architecture, Web Design and Development
------------------------------------------------------
We are the music makers, and we are the dreamers of
the dreams...
=============== =============== =============== =========
Dec 31 '06 #4

Kevin Scholl wrote:
Peter Michaux wrote:
Yanick wrote:
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

--
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 ***

=============== =============== =============== =========
Kevin Scholl http://www.ksscholl.com/
ks*****@comcast .DELETE.net
------------------------------------------------------
Information Architecture, Web Design and Development
------------------------------------------------------
We are the music makers, and we are the dreamers of
the dreams...
=============== =============== =============== =========
Dec 31 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3380
by: yurick | last post by:
Hello everybody, I'm quit newbie to XML/XSLT, would appreciate any help. There is XML like this: <person name="adam"/> <person name="eve"/> <person name="cain"> <parent name="adam"/>
6
11471
by: Gale | last post by:
I'm working on something in jQuery with XPath What I want to do is: if checkbox is checked, set background color od label that contain input(checkbox) to red I have this code: $("label]").css("background", "red"); but it doesn't working because of nested brackets ] and it freeze the browser
1
1898
by: DuaneMoraes | last post by:
A new book on jQuery, the powerful JavaScript library, has been announced by Packt In Learning jQuery, Karl Swedberg and Jonathan Chaffer, creators of the popular jQuery learning resource www.LearningjQuery.com, share their knowledge, experience, and enthusiasm about jQuery to help users get the most from the library and to make their web applications shine. jQuery is a powerful JavaScript library that can enhance websites regardless of the...
1
49872
by: mikeh3275 | last post by:
I'm new to developing in jQuery, so I'm probably doing this wrong. I'm loading a form into a modal dialog box and I'm trying to assign a click event to the button in the form, but I can't seem to get anything to happen. Below is the code. Thanks in advance. jQuery: jQuery(document).ready(function() { jQuery("a").click(function() { jQuery("#dialog").dialog({ modal: true,
20
2271
by: Aaron Gray | last post by:
There does not seem too be anyway to test if two jQuery references are the same element. Given :- ... <div id="1"></div .... Then :- alert( $("#1") == $("#1"))
26
3133
by: RobG | last post by:
Do some of the regulars here need to re-think their (sometimes strident) opposition to libraries? Both Microsoft and Nokia have announced support for jQuery. It seems to have gained quite a bit of momentum, can it be considered a reasonable choice for those who want to use a full-featured, well supported library? <URL: http://jquery.com/blog/2008/09/28/jquery-microsoft-nokia/ >
2
4552
by: souporpower | last post by:
Hi All I am trying to print some HTML using JQUERY. I am posting the code. I don't see the alert. It seems as though the function is not registered when the document is loaded. Can someone please clarify what I am doing wrong? BTW, I am using IE8 and Chrome to test. Sorry I can't place the code in a web site. Thanks for your help
53
8366
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script language="javascript" type="text/javascript">
5
4932
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
8262
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1507
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.