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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:41:27+00:00 2026-06-05T09:41:27+00:00

Problem: I have jQuery code that switch perfectly between tabs. However, I am wondering

  • 0

Problem:

I have jQuery code that switch perfectly between tabs. However, I am wondering how it can be extended so that it also activates the first sub element of each id.

Code for HTML tab navigation:

<div id="navtabs">
    <div>
        <a href="#tab1" class="active btn btn-info" data-toggle="tab"><i class="icon-home"></i>Start</a>
        <a href="#tab2" class="btn btn-info" data-toggle="tab"><i class="icon-book"></i>Essay</a>
        <a href="#tab3" class="btn btn-info" data-toggle="tab"><i class="icon-ok-sign"></i>Criteria</a>
        <a href="#tab4" class="btn btn-info" data-toggle="tab"><i class="icon-time"></i>Time</a>
    </div>
</div>

Code for example tab:

<div class="tab-pane" id="tab2">

    <ul id="myTab" class="nav nav-tabs">
        <li class="active"><a href="#participants" data-toggle="tab">Participants</a></li>
        <li><a href="#gradevalues" data-toggle="tab">Criteria</a></li>
    </ul>

    <div id="myTabContent" class="tab-content">
        <div class="tab-pane fade in active" id="participants">Text</div>
        <div class="tab-pane fade" id="gradevalues">Text</div>
    </div>

</div>

jQuery code:

$('#navtabs a[data-toggle="tab"]').on('shown', function () {
    $('#navtabs a[data-toggle="tab"]').attr('class','btn btn-info');
    $(this).attr('class','active btn btn-info');
})

Scenario:

When I click on the second tab (#tab2), I would like in addition to what the jQuery does now also:
(1) activate the first li element in #myTab
(2) activate the first div element in #myTabContent.

That is to say, always make sure that there is a "class=active" for the first li element and "class=tab-pane fade in active" for the first div.

  • 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-05T09:41:29+00:00Added an answer on June 5, 2026 at 9:41 am

    Try this:

    $('#navtabs a[data-toggle="tab"]').on('shown', function () {
        $('#navtabs a[data-toggle="tab"]').attr('class','btn btn-info');
        $(this).attr('class','active btn btn-info');
    
        var tabID = $(this).attr('href');
        var lis = $(tabID).find('#myTab li');//Get collection of li's
        $.each(lis, function(){
            $(this).removeClass('active'); //Remove the active class from each li
        });   
        $(tabID).find('#myTab li:eq(0)').addClass('active');//Add active class 
    
        //Same process for divs
        var divs = $(tabID).find('#myTabContent div');
        $.each(divs, function(){
            $(this).removeClass('in active');
        });
        $(tabID).find('#myTabContent div:eq(0)').addClass('in active');
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem to add jQuery to some existing code, please help. We have
hi im new to jquery and im facing these problem i have these code
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have a JQuery (using JQuery 1.4.2) problem that exhibits only in IE8 in
Fact: I'm not that good with jQuery. Problem: I have a form containing dynamically
I have a jquery code, but I'm a little bit confused on how can
In jQuery, I have written a piece of code that appears on every page
I have this jquery code that for a normal browser allows you to have
I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have some jQuery code that finds elements with the shaded CSS class and

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.