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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:03:06+00:00 2026-06-03T09:03:06+00:00

If I have an html structure like: <div id=parent> <div class=child first> <div class=sub-child></div>

  • 0

If I have an html structure like:

<div id="parent">
 <div class="child first">
   <div class="sub-child"></div>
 </div>

 <div class="child second">
   <div class="sub-child"></div>
 </div>

 <div class="child third">
   <div class="sub-child"></div>
 </div>
</div>

and I have a click handler defined through ($('#parent.child')).click() and then I click on the div with the class of second (first, second, third classes have simply been added to make demo clearer) is there a simple way to get the number 1 as it is the second child? (0 based index)?

Something like $(this).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-06-03T09:03:08+00:00Added an answer on June 3, 2026 at 9:03 am

    Just have a look at the jQuery API. The method you suggest, index, is exactly right:

    $('#parent .child').click(function() {
        var index = $(this).index();
    });
    

    From the docs:

    If no argument is passed to the .index() method, the return value is
    an integer indicating the position of the first element within the
    jQuery object relative to its sibling elements.

    Also note that I’ve changed the selector slightly from your example. I’m guessing that was just a typo in your question though. #parent.child will look for an element with ID “parent” and a class of “child”, but you actually want #parent .child (note the space) to find elements with class “child” that are descendants of an element with ID “parent”.

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

Sidebar

Related Questions

let's say I have an HTML structure like this: <div class=first> <div class=sub-1> <div
i have html structure like this <div> <span class=ic> <span class=ic>12345</span> </span> </div> i
Ok, so i have a HTML structure like this: <div class=content> <div id=a1 class=article>
I have a HTML structure like follows <div id=answer-1> <a class=edit></a> </div> <div id=answer-2>
I have some HTML with the following approximate structure and positioning: <div class=grand-parent style=position:
I have a html structure like this: <div class=one> <div id=two> <h2>Any</h2> <h4>Any</h4> </div>
I have html structure like below: <div id=banner-menu-holder> <div> <div class=avalible> <div class=items-holder> <div>
I have a html structure like : <div onmouseover=enable_dropdown(1); onmouseout=disable_dropdown(1);> My Groups <a href=#>(view
I have this html structure <div class=top_menu> <ul> <li class=left><a href= class=family-filter>asdas</a></li> <li class=welcome>Welcome
Assuming I have this HTML structure: <ul class='menu'> <li> <div></div> <div> <div></div> <div> <a

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.