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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:54:37+00:00 2026-05-25T13:54:37+00:00

I am making some tabbed content, I have the tabs inline and overlapping each

  • 0

I am making some tabbed content, I have the tabs inline and overlapping each other slightly, meaning they have three states: inactive tab (“it” class), active tab (“at” class) and trailing tab (“tt” class) which follows the active tab. In the code sample below, tab three is active and tab four is the trailing tab as it comes after it.

<div id="tabnest">
    <div id="tab" class="it"><a href="#" onclick="#">Tab One</a></div>
    <div id="tab" class="it"><a href="#" onclick="#">Tab Two</a></div>
    <div id="tab" class="at"><a href="#" onclick="#">Tab Three</a></div>
    <div id="tab" class="tt"><a href="#" onclick="#">Tab Four</a></div>
    <div id="tab" class="it"><a href="#" onclick="#">Tab Five</a></div><br>
</div>
<div id="content">
</div>

I’m a total newbie to JavaScript I’d like each tab when clicked to:
1. change all the other tabs classes to “it”,
2. change the current, clicked tab class to “at” and
3. change the next tabs class to “tt” if one exists.

From research on the net, I understand that these are the functions I want roughly:

document.getElementById('tab').nextSibling;
document.getElementById('tab').className = "it";

I just don’t know how to call a function and stich it up together. Sorry for the complicatedness of this, if it’s impossible to call the next div/tab and change its class solely then don’t worry, could you just help me change the selected tabs class and all the others please? Thanks in advance.

  • 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-25T13:54:37+00:00Added an answer on May 25, 2026 at 1:54 pm

    See http://jsfiddle.net/E7jnq/1/ for a jQuery implementation, or http://jsfiddle.net/ryMH3/ for a vanilla JS implementation.

    jQuery:

    $(document).ready(function()
    {
        $('#tabnest a').click(function()
        {
            $(this).parent().parent().find('div').removeClass('at').removeClass('tt').addClass('it'); // Set everything to 'it'
            $(this).parent().addClass('at'); // Set this div to 'at'
            if ($(this).parent().next('div').length > 0)
            {
                $(this).parent().next('div').addClass('tt');
            }
        });
    });
    

    Vanilla JS:

    var tabNest = document.getElementById('tabnest');
    var tabs = getElementsByClassName('tab');
    
    
    for (i = 0; i < tabs.length; i++)
    {
        addEventListener(tabs[i], 'click', function ()
        {
            for (i = 0; i < tabs.length; i++)
            {
                if (tabs[i] == this)
                    this.className = 'tab at';
                else if (tabs[i - 1] == this)
                    tabs[i].className = 'tab tt';
                else
                    tabs[i].className = 'tab it';
            }
            this.className = 'tab at';
    
        }, false);
    }
    
    function getElementsByClassName(classname, node)
    {
        if(!node) node = document.getElementsByTagName("body")[0];
        var a = [];
        var re = new RegExp('\\b' + classname + '\\b');
        var els = node.getElementsByTagName("*");
        for(var i=0,j=els.length; i<j; i++)
            if(re.test(els[i].className))
                a.push(els[i]);
        return a;
    }
    
    function addEventListener(element, eventType, handler, capture)
    {
        if (element.addEventListener)
            element.addEventListener(eventType, handler, capture);
        else if (element.attachEvent)
            element.attachEvent("on" + eventType, handler);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im making some script with mechanize.browser module. one of problem is all other thing
I am programatically making some LinkButtons, and they worked fine for a while, but
I am making some small business intelligence applications/tools that need to talk to other
Im making some of my ajax visible for google. To do that, I have
After making some changes to a method, I find it utterly annoying to have
I'm making some kind of movie with a webpage. For that I have to
I'm making some examples for javascript; they are not really usable. This one is
I have some sql script files where i am making some DDL changes as
I have a Java program making some JNI calls to a native library (mylib.so).
I have some screens making some data queries that might take a long time.

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.