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 6921733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:18:53+00:00 2026-05-27T10:18:53+00:00

In the code below, I am trying to get back the index of the

  • 0

In the code below, I am trying to get back the index of the element clicked and if so, its parent index. The problem is that it tries to return, also, its parent’s index…

By example: if I click on “1” the alert will give back 0,0 which is good.
If I click on A2, the alert will return 0,1 (which is also good) and then return 1,0 (the parent “coordinate”) !!!
I want to keep it to return the parent array…

<ul>
    <li>1</li>
    <li>2
    <ul>
        <li>A2</li>
        <li>B2</li>
        <li>C2</li>
    </ul>
    </li>
    <li>3</li>
    <li>4</li>
    <li><5</li>
</ul>


$('#control ul li').click(function(e) { 
    e.preventDefault();

    var child = $(this).index(); // Get actual li element index
    var parent = $(this).parents('li').index(); // Get the later parent index
    if(parent === -1) { parent = 0; } // If it doesn't have a parent set -1 to 0
    var current = $.makeArray([child,parent]); // Make an array of the coordinate 

    alert(current);


    switcher(current);
});
  • 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-27T10:18:54+00:00Added an answer on May 27, 2026 at 10:18 am

    You should stop the event propagation. Try this

    $('#control ul li').click(function(e) { 
       e.stopPropagation();
    
       var child = $(this).index(); // Get actual li element index
       var parent = $(this).parents('li').index(); // Get the later parent index
       if(parent === -1) { parent = 0; } // If it doesn't have a parent set -1 to 0
       var current = $.makeArray([child,parent]); // Make an array of the coordinate 
    
       alert(current);
    
    
       switcher(current);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems trying to get the code below to output the data
I have a C extension (code below) in which I'm trying to get access
I'm trying to get from Line #1 to Line #2 in the below code:
The code below is what I am trying to use in order to get
Thank you for reading this Question. CODE BELOW I'm trying to get a jsp
I'm calling a jQuery GET on the test.php file code below. I'm trying to
Can't seem to figure this out, see code below. Trying to make a GET
I have the code below: from the getData function im trying to call get_xml
In the code below i`m trying to read a list of selected projects and
In the code below I'm trying to load some images and put them in

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.