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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:27:34+00:00 2026-05-21T18:27:34+00:00

I have an unordered list, with a couple list-items inside. Inside each of those

  • 0

I have an unordered list, with a couple list-items inside. Inside each of those is a link. What I want to do is find the position of the list-item when someone clicks the link inside it.

For example, if someone clicks the link inside the 3rd list-item, it gives me a value of 3.

I already have the click part, just need to figure out how to get the position of the list-item

Javascript only

  • 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-21T18:27:35+00:00Added an answer on May 21, 2026 at 6:27 pm

    Here’s a simple live example that does what you want (except the list does not have links)

    http://jsfiddle.net/8k926/2/

    In the “Result” box click on one of the list items. It will have a handler that pops up its sequence number.

    The Javascript code is the following

    var els = document.getElementsByTagName('li');
    
    Array.prototype.forEach.call(els,function(el,i){
        el.addEventListener('click', function(){alert(i);}, false);
      }) ;
    

    Although els is array-like, it does not have a forEach method. We get around that by using the Array.prototype.forEach method.

    Update: Here’s a second live example that narrows things down to a specific list, as opposed to all list items.

    http://jsfiddle.net/8k926/3/

    Also, as a commenter points out, forEach is not universally supported, but it is used here to simplify the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unordered list with five list items, each with a link inside
I have an unordered list with five list items, each with a link inside
I have an unordered list of items, I want to display each item as
I have an unordered list with several divs contained inside. Each list item is
I have an unordered list and each of the item in the ul has
I have an unordered list, each list item has an id (id=6~OriginalName) - when
I have an unordered list inside a div with a background image for each
I have an unordered list with each list item background changing color when the
I have an unordered list with elements and I want to append an item
I have an unordered list and I want to have the list items have

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.