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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:36:17+00:00 2026-05-29T03:36:17+00:00

So, I have a nav element with an unorder list that I use as

  • 0

So, I have a nav element with an unorder list that I use as tabs. There are three, you click one and it shows a div in the website. However, I want it so that if you click another, it will hide the one currently being shown, and then show the one you clicked. But I can’t seem to get it right. Here is the function I have:

function display(action, id)
 {
 if (action == 'show')
 {
 document.getElementById("page"+id).style.display = "block";
 document.getElementById("link"+id).href= "javascript:display('hide', "+id+")";
 }

if (action == 'hide')
 {
 document.getElementById("page"+id).style.display = "none";
 document.getElementById("link"+id).href= "javascript:display('show', "+id+")";
 }
 }

</script>

I tried to do something like

document.getElementById(“page”+id+1).style.display = “none”;

I thought that it would change the display style to none of the div with an id one more than the current, but instead it does nothing. What would I add to this to have it hide all currently open tabs?

  • 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-29T03:36:18+00:00Added an answer on May 29, 2026 at 3:36 am

    also you can store the DIV name in a Hidden Input

    http://jsfiddle.net/we2AJ/

    <body>
        <script language="javascript">
            function MyFunction(divName){
    
            //hidden val
            var hiddenVal = document.getElementById("tempDivName"); 
    
            //hide old
            if(hiddenVal.Value != undefined){
                var oldDiv = document.getElementById(hiddenVal.Value); 
                oldDiv.style.display = 'none'; 
            }
    
            //show div
                var tempDiv = document.getElementById(divName); 
                tempDiv.style.display = 'block';              
    
            //save div ID
                hiddenVal.Value = document.getElementById(divName).getAttribute("id");
    
            }
        </script>
        <input id="tempDivName" type="hidden" />
        <ul>
            <li><a href="#" OnClick="MyFunction('myDiv1');">Show myDiv1</a></li>
            <li><a href="#" OnClick="MyFunction('myDiv2');">Show myDiv2</a></li>
            <li><a href="#" OnClick="MyFunction('myDiv3');">Show myDiv3</a></li>
        </ul>
        <br/>
        <div id="myDiv1" style="background-color:red; height:200px; width:200px; display:none">
            myDiv1
        </div>
        <div id="myDiv2" style="background-color:yellow; height:200px; width:200px; display:none">
            myDiv2
        </div>
        <div id="myDiv3" style="background-color:green; height:200px; width:200px; display:none">
            myDiv3
        </div>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic website nav layout that looks like this: <li class=folder parent_folder>
So I have a bunch of tabs that are all inside of a list
Here's the idea: I have a div element, #content_wrapper, which encompasses three floated divs,
I have a nav bar that when I over over an element the next
I have nav code like this in my HTML file: <div id="center_links"> <ul> <li><a
I have a nav that has subnavs. When the user hovers over the li's
I have a simple nav made up of the following HTML; <div class=inner> <div
I have built a nav where I have an unordered list made up of
I want to have my list (nav) align to the center of an image
I have this nav that uses addClass('hover') when the mouse is rolled over an

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.