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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:39:54+00:00 2026-05-26T03:39:54+00:00

I have a DOM structure that looks like this: <div class=chapter> <section></section> <section></section> </div>

  • 0

I have a DOM structure that looks like this:

<div class="chapter">
   <section></section>
   <section></section>
</div>
<div class="chapter">
   <section></section>
   <section></section>
   <section class="current"></section>
   <section></section>
</div>
<div class="chapter">
   <section></section>
   <section></section>
   <section></section>
   <section></section>
</div>

I want to get the index number of the section with a class of “current”, across all sections. In this example the index of that would be 5, since it’s the 5th section tag and contains a class of current.

How do I get this with jQuery?

I’ve started with this to get a list of all sections in the dom:

var sections = $('section');

I’ve tried things like this to try and get the result I want:

alert($(sections+'.current').index());

That returns a js error.

What am I missing here? Thanks!

  • 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-26T03:39:54+00:00Added an answer on May 26, 2026 at 3:39 am

    In your code $('section') would return you all the sections as a jquery object. Amongst them to get the index of a section which has a class of current you could do this:

    sections.index($(".current"));
    

    This would return you a relative index of the section with class current, which would be 4 as
    $('sections') would return you a jQuery object Array(0 indexed) which contains all the sections elements. So the element which matches is the 5th element and index would return 4.
    Hope this fiddle helps.

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

Sidebar

Related Questions

I have a DOM structure that looks like this: <div id=comment-1234 class=comment>...</div> <div id=comment-2391
So I have a DOM document that looks essentially like this <categories> <category id=1/>
I have this structure in my dom: <label>London<input type=checkbox name=London></label><br> <div class=innerpost> <label>N1 2AB<input
I have a dom structure that looks something like (although a lot more complex)
I have this HTML structure: <div class=start> <div class=someclass> <div class=catchme> <div=nested> <div class=catchme>
I have the following DOM structure: /*:DOC += <div id='testDiv' class='testDivClass'><div id='innerTestDiv'></div></div><span id='testSpan' class='testSpanClass'><span
I have the following DOM structure (unordered list), that I would like to sort
I have this HTML structure and want to convert it to an accordion. <div
I have the following DOM structure / HTML, I want to get (just practicing...)
I have the following DOM structure: <div class=city> <div class=a>Delete</div> <div class=b>Selected</div> <div class=c>Delete</div>

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.