Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1105321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:36:49+00:00 2026-05-17T01:36:49+00:00

I have this html page which globally exists of div , section , and

  • 0

I have this html page which globally exists of div, section, and ul elements (of course some more, but those are the most common)

Now in my fourth list on the page (e.g. below in bold)


<body>
 <div>
  <header>
   <ul id="firstList">
    <li>
    [..]
  <section>
   <ul id="secondList">
    [..]
  <section>
   <ul id="thirdList">
   [..]
  <section>
   <ul id="fourthList">
    <li><a>Test 1</a></li>
    <li><a>Test 2</a></li>
    <li><a>Test 3</a></li>
   </ul>
  [..]

The thing is that, when someone clicks on a test, i want to loop through the list-items to look the position of the click up in the list (it there are items before or after)

Herefore i have the following


$("a").click(function(event){
 [..]
 var parentEl = $(this).parents('ul').filter(":first").tagName;
 alert($(parentEl).attr("id"));
});

But this gives me firstList as an output. I assume jQuery looks through the document from top down, so the output with filter(:first) (oh and get(0)) as well makes sence i guess.. But how am i going to get the first parent of the clicked link?

If someone click on Test 2 i want to get fourthList as an output (and eventually the position, but that’s for later)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:36:50+00:00Added an answer on May 17, 2026 at 1:36 am

    Try this

    $("a").click(function(event){
      [..]
      var $parentEl = $(this).closest('ul');
      alert( $parentEl.attr("id") );
    });
    

    And to get the position of the link among it’s siblings

    $("a").click(function(event){
      [..]
      // returns the 0-based index of the `li` among it's sibling `li`s
      var idx = $(this).parent().prevAll().length;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have this html page containing some links in it which are at
I have this html page which is very simple, it contains a text box
I have this HTML in my page <div id='masterDIV'> <div id='divItemNumber'>23</div> <div id='divDesc'>This is
I have simple HTML page with svg like this: <div id=plan> <svg xmlns=http://www.w3.org/2000/svg version=1.1>
In this html I basically have a sidebar-div and a page-div with the header,
I have an HTML page that roughly looks like this: <div id=rolesRollerBody style=height: 309px;>
I have this code in my html page: <body> <div align=center> <a href=../index.html> <img
I have created a html page which has a div displaying image.I have to
I have this html page with the form <form method=post id=form1 name=form1 action=/status_comment/save> //Some
I've got several elements on a HTML page which have the same class -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.