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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:58:08+00:00 2026-05-16T20:58:08+00:00

I am using jquery to load content into tabs, and switch the tabs on

  • 0

I am using jquery to load content into tabs, and switch the tabs on click. My problem is that one one page I am using this “tab switcher” twice, and it is causing a conflict. I am not too experienced with jquery, so my problem probably lies in the fact that I am creating the function twice in the head. Here is my jquery (you will notice that there are duplicate scripts, with the selectors changed up a bit so the “tab switchers” appear different.

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

        //When page loads...
        $(".tab_content").hide(); //Hide all content
        $("ul.tabs li:first").addClass("active").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content

        //On Click Event
        $("ul.tabs li").click(function() {

            $("ul.tabs li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
            return false;
        });

    });
    </script>

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

        //When page loads...
        $(".tabs_content").hide(); //Hide all content
        $("ul.tab li:first").addClass("active").show(); //Activate first tab
        $(".tabs_content:first").show(); //Show first tab content

        //On Click Event
        $("ul.tab li").click(function() {

            $("ul.tab li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tabs_content").hide(); //Hide all tab content

            var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active ID content
            return false;
        });

    });
    </script>

My css is all correct, I know the problem is above.The second script works fine, and the first script doesn’t.

You can see this live here: link You will notice that the second script works fine (at the bottom : margie and todd. And the first script doesn’t work (in the sidebar :categories and archives.)

Any idea how to fix this?

  • 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-16T20:58:09+00:00Added an answer on May 16, 2026 at 8:58 pm

    I know that script – I actually refactored it for another question. The code is pretty bad, in the sense that it contains many bad practices. Let’s see what can be done here:

    $(".tabs_content").not(':first-child').hide();
    var tabs = $('.tabs li');
    
    tabs.filter(':first-child').addClass('active');
    
    tabs.click(function() {
        var current = $(this);
    
        if(!current.hasClass('active')){
            current.addClass('active').siblings().removeClass('active');
            var activeTab = current.find("a").attr("href");
            current.parent().next().children().hide().filter(activeTab).fadeIn();
        }
    
        return false;
    });
    

    There – a single script for all your tabs. Rename all your tab containers to tabs. This uses some pretty heavy chaining, which really isn’t very efficient, but given the DOM here there isn’t much to do. Use this so you won’t need two scripts that do essentially the same thing.

    See it working here: http://jsfiddle.net/E3SFt/2/. I copied your HTML character for character for this, with the minor modification to the class names as noted above. Also note that you’ve got some invalid HTML in there – li elements inside divs is not valid.

    Edit: Stupid mistake, this.hasClass should be current.hasClass

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

Sidebar

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.