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

  • Home
  • SEARCH
  • 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 7914887
In Process

The Archive Base Latest Questions

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

I have a class of multiple ‘DIV’ elements and inside it are list of

  • 0

I have a class of multiple ‘DIV’ elements and inside it are list of ‘p’ elements. See below:

<div class="container">
    <p>This is content 1</p>
    <p>This is content 2</p>
    <p>This is content 3</p>
</div>
<div class="container">
    <p>This is content 1</p>
    <p>This is content 2</p>
    <p>This is content 3</p>
</div>

Here’s my jQuery code on calling the ‘p’ elements through hover:

$('.container').children('p').hover(function(){
    //get the nth child of p from parent class 'container'
});

How can I get the nth child number of the element ‘p’ from its parent container class ‘container’?

Like if you hover

This is content 1

it should trigger output as 1;

  • 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-03T14:16:13+00:00Added an answer on June 3, 2026 at 2:16 pm

    You can use jQuery’s index function for that. It tells you where the given element is relative to its siblings:

    var index = $(this).index();
    

    Live example | source

    The indexes are 0-based, so if you’re looking for a 1-based index (e.g., where the first one is 1 rather than 0), just add one to it:

    var index = $(this).index() + 1;
    

    If you’re not using jQuery and came across this question and answer (the OP was using jQuery), this is also quite simple to do without it. nth-child only considers elements, so:

    function findChildIndex(node) {
        var index = 1;                         // nth-child starts with 1 = first child
        // (You could argue that you should throw an exception here if the
        // `node` passed in is not an element [e.g., is a text node etc.]
        // or null.)
        while (node.previousSibling) {
            node = node.previousSibling;
            if (node && node.nodeType === 1) { // 1 = element
                ++index;
            }
        }
        return index;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class that tries multiple methods of getting data from Google maps
I have multiple divs in my page as: <div imageId='image5' name='5' class='speechBubble'> <div imageId='image5'
I have multiple elements with class test . If I hover them, they should
I have a class which holds multiple filenames inside a TStringList. I can access
I have this class and I have a loop that launches multiple threads from
In Django, when you have a parent class and multiple child classes that inherit
I have a class that refers to UiApplication.getUiApplication() multiple times, would there be any
If we have a class that inherits from multiple interfaces, and the interfaces have
I have multiple images that have the same class attribute and I want to
Let's say I have a static class with a static method. Multiple threads can

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.