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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:58:49+00:00 2026-06-14T01:58:49+00:00

I use code from this tutorial: jacklmoore.com/notes/jquery-tabs. <ul class=’tabs’> <li><a href=’#tab1′>Tab 1</a></li> <li><a href=’#tab2′>Tab

  • 0

I use code from this tutorial: jacklmoore.com/notes/jquery-tabs.

<ul class='tabs'>
    <li><a href='#tab1'>Tab 1</a></li>
    <li><a href='#tab2'>Tab 2</a></li>
    <li><a href='#tab3'>Tab 3</a></li>
</ul>
<div id='tab1'>
    <p>Hi, this is the first tab.</p>
</div>
<div id='tab2'>
    <p>This is the 2nd tab.</p>
</div>
<div id='tab3'>
    <p>And this is the 3rd tab.</p>
</div>

script:

$('ul.tabs').each(function(){
    // For each set of tabs, we want to keep track of
    // which tab is active and it's associated content
    var $active, $content, $links = $(this).find('a');

    // If the location.hash matches one of the links, use that as the active tab.
    // If no match is found, use the first link as the initial active tab.
    $active = $($links.filter('[href="'+location.hash+'"]')[0] || $links[0]);
    $active.addClass('active');
    $content = $($active.attr('href'));

    // Hide the remaining content
    $links.not($active).each(function () {
        $($(this).attr('href')).hide();
    });

    // Bind the click event handler
    $(this).on('click', 'a', function(e){
        // Make the old tab inactive.
        $active.removeClass('active');
        $content.hide();

        // Update the variables with the new link and content
        $active = $(this);
        $content = $($(this).attr('href'));

        // Make the tab active.
        $active.addClass('active');
        $content.show();

        // Prevent the anchor's default click action
        e.preventDefault();
    });
});

I want to modify this script to add/remove class ‘active’ to parent li element of a. I tried to replace $active.addClass('active'); with $active.parent('li').addClass('active');, but behavior of resulted code is not good.

  • 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-14T01:58:52+00:00Added an answer on June 14, 2026 at 1:58 am

    You just need to remove the active class from the previously clicked element:

    // Make the old tab inactive.
    $active.parent('li').removeClass('active');
    

    You also need to add the active to the first list element as well:

    // If no match is found, use the first link as the initial active tab.
    $active.parent('li').addClass('active');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use code from this tutorial: jacklmoore.com/notes/jquery-tabs . <ul class='tabs'> <li><a href='#tab1'>Tab 1</a></li> <li><a
I use this tutorial http://www.raywenderlich.com/2797/introduction-to-in-app-purchases for create purchases in my app. From time to
I use the code from Sun's java tutorial import java.net.*; import java.io.*; public class
I'm trying to use the django-voting tutorial from this blog: http://new.justinlilly.com/blog/2008/nov/04/django-voting-a-brief-tutorial/ to get a
I downloaded Ray Wenderlich's simple contact listener from this tutorial: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone Currently I am
Borrowing this code from several different tutorials on how to use Google maps on
how does one use code to do this: produce 15 random numbers [EDIT: from
I am learning to use xmlhttprequest/AJAX. In this sample code from w3schools, I do
I use this code to select password field from the sql server 2012 db,
I use this code which is taken from MVC futures and attach the Attribute

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.