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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:19:32+00:00 2026-06-11T13:19:32+00:00

How do I get the nth-child param value with a class selector that is

  • 0

How do I get the nth-child param value with a class selector that is equal to “active” in jQuery?

I’m not sure if this is logical but I want to determine which of the list of dd elements that I have is currently selected through the nth-param value.

The code is actually a loop of vertical tabs from Foundation’s Vertical Tabs.

<dl class="vertical tabs">  
<?php foreach($tabs as $key):?>
    <dd id="ver_tab"><a href="javascript:void(0)" onclick="ajaxFunc('<?php echo ($key['group_name']) ?>')" id="ver_tab_a"><?php echo ucwords($key['group_name']);?></a></dd>        
<?php endforeach ?>
    <dd><a id="new_group_button" href="#new_group_form">+ New Group</a></dd>

I have a list of tabs with data acquired dynamically. I also have a static tab at the bottom which would add a new group. A click on a tab from the dynamically generated tab would add a class with value “active” What I want is when I click the static tab, a modal is open and when I cancel the modal(modal is from Foundation’s Reveal also), the selected tab should revert to the active tab before I click the static tab.

On my jQuery I have:

$("#ver_tab:nth-child("+x+")").attr("class","active");

To revert to the previously selected tab where the x is the nth-child of the selected tab.

Thanks so much!

  • 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-11T13:19:34+00:00Added an answer on June 11, 2026 at 1:19 pm

    I finally figured it out after a long search.

    Although this answer is on different approach, nevertheless it solve my problem on how to identify the index number of my currently selected tab.

    Here’s what I did.
    On my:

    <dd id="ver_tab"><a href="javascript:void(0)" onclick="ajaxFunc('<?php echo ($key['group_name']) ?>')" id="ver_tab_a"><?php echo ucwords($key['group_name']);?></a></dd>
    

    I added another paramater on the:

    onclick="('<?php echo ($key['group_name']) ?>')"
    

    So it looks like:

    onclick="('$(this)','<?php echo ($key['group_name']) ?>')"
    

    Then on my ajaxFunc:

    function ajaxFunc(x, group_name){
        var pos = x.closest("dd").index;
    }
    

    The pos variable should now contain the index value of currently selected tab.

    Thanks to this post Jquery index can't find element (-1) wrong input (with live function)! Save me so much time!

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

Sidebar

Related Questions

I have this jquery that is working on the firebug console: $('#transaction_list>tbody>tr>td:nth-child(2)').each( function(){$(this).toArray();}) And
Unless it's not supposed to but I can't seem to get nth-child to acknowledge
If I run this code, var waitRow = $(this).parent().parent().next().get(0); $(waitRow).children('td:nth-child(2)').html('some text').toggle(); toggle is not
Is it possible to get jQuery to do the same job as nth:child(odd)? So
Is it possible to get the 'nth' return value from a function without having
parentId=$(this).closest('tr').find('td:nth(6)')[0].textContent; I am trying to get ID from flexigrid column. It works fine in
I'm using the following code to get the value of variable one in jQuery
<div class=second> <div class=selector id=selFirst></div> <div class=selector id=selSecond></div> <div></div> </div> How to get #selFirst
Is there a way to only affect visible elements with this css? table.grid tr.alt:nth-child(odd)
Possible Duplicate: Get Nth child of a node using xpath How can I access

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.