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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:08:26+00:00 2026-06-04T09:08:26+00:00

I have divs with same class, but each 3 are wrapped in a parent

  • 0

I have divs with same class, but each 3 are wrapped in a parent div. I can’t get the index the way I want it. I am sorry, could anyone help me to get the index as number from 0 to 8.. when i click on any element? despite the parent element.

Here is my full code for your testing.

<div class="more-content">
    <div class="post">post 1</div>
    <div class="post">post 2</div>
    <div class="post">post 3</div>
</div>
<div class="more-content">
    <div class="post">post 4</div>
    <div class="post">post 5</div>
    <div class="post">post 6</div>
</div>
<div class="more-content">
    <div class="post">post 7</div>
    <div class="post">post 8</div>
    <div class="post">post 9</div>
</div>

<script type="text/javascript">
$(function() {

    // navigate posts with next/prev buttons
    $(".post").click(function(){
        alert($(this).index());
    });

});
</script>

If i click i get index 0, 1, 2 ..i think because each 3 items are wrapped in parent? I am new with jquery, any help appreciated. what i need is get the index of post with same class.. say post 6 = index 5.. and so on

UPDATE
How can I get the same result if the clicked element is a child anchor in the post div and not the post div directly?

  • 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-04T09:08:27+00:00Added an answer on June 4, 2026 at 9:08 am

    Try index method with this as an argument:

    $(".post").click(function() {
        alert($(".post").index(this));
    });​
    

    DEMO: http://jsfiddle.net/Nryf3/

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

Sidebar

Related Questions

i have 5 div's of the same class but different id stacking on top
I have displayed a row of items with same div class name but different
i have multiple divs with the same class on my page. I want to
i have two divs with the same ids but one has display=none and the
i have many div's with the same background image and i want change this
I have a set of divs with the same class. I need to give
I have an application creating a bunch of divs through a loop. Each div
I have two sibling divs sitting below each other, both contained in the same
I have to follow divs: <div id=cont> <div class=row> <div class=col>1</div> <div class=col>example.com</div> <div
I have a set of divs which are specified under the same class name,

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.