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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:48:37+00:00 2026-06-01T14:48:37+00:00

I have created tab style interface using css and javascript with only two tabs

  • 0

I have created tab style interface using css and javascript with only two tabs which is working fine.But i want to add more tabs to it and i am not getting how can i write javascript code for it to show current active tab and its contents and hide all other tabs and their contents


Following is my html code :

<div id="container">

    <div id="tabbox">
        <a href="#" id="signup" class="tab signup">Signup</a>
        <a href="#" id="login" class="tab select">Login</a&gt;
    </div>

    <div id="panel">
        <div id="loginbox">Login Form</div>
        <div id="signupbox"&gt;Signup Form</div>
    </div>

</div>

This is my javascript code :

$(document).ready(function()
{

    $(".tab").click(function()
    {
        var X=$(this).attr('id');

        if(X=='signup')
        {
            $("#login").removeClass('select');
            $("#signup").addClass('select');
            $("#loginbox").slideUp();
            $("#signupbox").slideDown();
        }
        else
        {
            $("#signup").removeClass('select');
            $("#login").addClass('select');
            $("#signupbox").slideUp();
            $("#loginbox").slideDown();
        }

    });

});

This is working fine for two tabs but if i add more tabs to it say :

<div id="container">

      <div id="tabbox">
          <a href="#" id="signup" class="tab signup">Signup</a>
          <a href="#" id="login" class="tab select">Login</a&gt;
          <a href="#" id="basic" class="tab basicinfo">Basicinfo</a>
          <a href="#" id="contact" class="tab contact info">contactinfo</a>
      </div>

      <div id="panel">
          <div id="loginbox">Login Form</div>
          <div id="signupbox"&gt;Signup Form</div>
          <div id="basicbox">Basic information</div>
          <div id="contactbox">Contact information</div>
      </div>

</div>

Then if i use previous javascript function i will have to add lot more lines to it and i am not getting how can i do it in short and simple way.
What changes do i have to make in my javascript function..

  • 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-01T14:48:38+00:00Added an answer on June 1, 2026 at 2:48 pm

    You are mixing ids (that have to be unique – you are using them multiple times) and classes in a weird way (you did before your edit…).

    For a basic setup like:

    <div id="container">
    
          <div id="tabbox">
              <a href="#A" class="tab">A</a> <!-- note the URL fragments pointing to actual ids -->
              <a href="#B" class="tab">B</a>
              <a href="#C" class="tab">C</a>
              <a href="#D" class="tab">D</a>
          </div>
    
          <div id="panel">
              <div id="A" class="tab">A Content</div> <!-- ID attributes are only used once -->
              <div id="B" class="tab">B Content</div>
              <div id="C" class="tab">C Content</div>
              <div id="D" class="tab">D Content</div>
          </div>
    
    </div>​​​​​​​​​​​​​​​​
    

    You could just use some lines of jQuery to get things working:

    $('div.tab').hide().first().slideDown(); //show first
    
    $('a.tab').click(function(){
        var targetID = $(this).attr('href'); //store element that triggered the click event
        $('div.tab:visible').slideUp(function(){ //hide visible tab
            $(targetID).slideDown(); //slide down newly selected tab
        });
    });​
    

    See a working fiddle

    Also read about ids and classes at MDN

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

Sidebar

Related Questions

I'm using primefaces' accordion panel. Inside the tabs i have forms which are created
I have created an HTML page which uses simple CSS (no javascript) for menu
I am new to this iphone development.I have created a tab bar application which
I have created a horizontal menu with 5 tab options using a ul and
I have created an application which needs to have a profile box tab which
I have a Tab Bar Controller created in Interface Builder Within the Tab Bar
I have a table which is created dynamically. Sometimes it can have two columns
within a ascx (usercontrol) I have a created a tab section which contains a
I have created an application having tab activity which in turn has 5 different
I have the following script: http://jsfiddle.net/oshirowanen/mYx5y/4/ I have created my own tab buttons which

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.