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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:33:52+00:00 2026-05-24T06:33:52+00:00

I try to understand how the jQuery Object Accessors index() works. But I don’t

  • 0

I try to understand how the jQuery Object Accessors index() works. But I don’t understand anything! (see http://jsfiddle.net/St4D7/)

So I have a HTML list item:

<ul>
<li>test 1</li>
<li>test 2</li>
<li>test 3</li>
</ul>

And jQuery:

$('ul li').click(function(){
    console.log($(this).index());
});

I’d like to have the index position of items on click (like 1, 2 or 3), that’s all. Please help.

PS : I don’t want to use each() or eq()… just index().

  • 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-24T06:33:54+00:00Added an answer on May 24, 2026 at 6:33 am

    As described in the documentation, index returns the zero-indexed position of the first element depending on the parameters you provide, in the jQuery object you call it on.

    However, you also seem to be slipping up on the context of this.

    At the time you call $(this).index(), this points to the lil element that was clicked on. Therefore $(this) contains a jQuery object containing one element.

    Instead, try something like this:

    var obj = $('ul li').click(function(){
        console.log(obj.index(this));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to try to a lib ala jquery but I don't understand why
I don't understand how work an object with Jquery/javascript. And how create a private
I used mmap(just try to understand how mmap works) to allocate 96k anonymous memory,
I can fix the below exception with a try-catch loop but I cannot understand
Consider the code below. I don't understand why my GCC compiler does not try
i try to use jQuery.noConflict() but in window.load function i get a $ is
Well I just implement jquery-ui-autocomplete with VB.net in the server side, but it was
Sorry, but apparently I don't understand chaining enough to figure out this problem... I'm
I try to understand the memory management in ObjectiveC and still some things are
I'm new to win32 API programming and I try to understand source code of

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.