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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:07:59+00:00 2026-06-10T04:07:59+00:00

thanks you for paying attention on my issue here. I am a total beginner

  • 0

thanks you for paying attention on my issue here. I am a total beginner for PHP and jQuery programming. Now I am trying to create a very simple function to show and hide multi-layer divs. For example, when you click “show div 1”, the corresponding content under div 1 will be shown (this is div 1 contents). After that you still can click the content under div 1 to show lower level contents (graph1). I got all these worked properly. However, when I click “show div 2”, the div 2 contents (this is div 2 contents) will be shown but the lower level contents of div 1 is still there (graph1). What I want is the lower content of div 1 is shown, and then I click show div 2, the lower content of div 1 will be hidden and only show div 2 contents. The following is my codes, thank you guys in advance~

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>show and hide try</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script>
function showStock(n)
{
document.getElementById("div"+n).style.display = 'block'
return false;
}

function hideStock(n)
{
for (x=1; x<=10; x++)
{
document.getElementById("div"+x).style.display = 'none'
}
document.getElementById(n).style.display = 'block'
return false;
}

function toggleStock(id)
{
    for (x=1; x<=3; x++)
    {
        document.getElementById("div"+x).style.display = 'none';
    }

    document.getElementById(id).style.display = 'block';
}

</script>


<script>
function showGraph(m)
{
document.getElementById("graph"+m).style.display = 'block'
return false;
}

function hideGraph(m)
{
for (y=1; y<=10; y++)
{
document.getElementById("graph"+y).style.display = 'none'
}
document.getElementById(m).style.display = 'block'
return false;
}

function toggleGraph(id)
{
    for (y=1; y<=3; y++)
    {
        document.getElementById("graph"+y).style.display = 'none';
    }

    document.getElementById(id).style.display = 'block';
}

</script>

</head>

<body>

<table width="50%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>
<a href="#" onClick="toggleStock('div1');return false;">show div 1</a> &nbsp;
<a href="#" onClick="toggleStock('div2');return false;">show div 2</a> &nbsp;
<a href="#" onClick="toggleStock('div3');return false;">show div 3</a>
</td>
</tr>
</table>

<div id="div1" style="display: none; border:1px solid black;">
<table border=1 width=25% cellspacing="0" cellpadding="0">
<tr><td><a href="#" onClick="toggleGraph('graph1');return false;">this is div 1 contents</a></td></tr>
</table>
</div>

<div id="div2" style="display: none; border:1px solid black;">
<table border=1 width=25% cellspacing="0" cellpadding="0">
<tr><td><a href="#" onClick="toggleGraph('graph2');return false;">this is div 2 contents</a></td></tr>
</table>
</div>

<div id="div3" style="display: none; border:1px solid black;">
<table border=1 width=25% cellspacing="0" cellpadding="0">
<tr><td><a href="#" onClick="toggleGraph('graph3');return false;">this is div 3 contents</a></td></tr>
</table>
</div>

<div id="graph1" style="display: none; border:1px solid black;">graph1</div>
<div id="graph2" style="display: none; border:1px solid black;">graph2</div>
<div id="graph3" style="display: none; border:1px solid black;">graph3</div>
</body>
</html>
  • 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-10T04:08:00+00:00Added an answer on June 10, 2026 at 4:08 am

    Replace your code with this, Hope it will help you

    function toggleStock(id)
    {
        for (x=1; x<=3; x++)
        {
            document.getElementById("div"+x).style.display = 'none';
        }
    
        document.getElementById(id).style.display = 'block';
      toggleGraph(id);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to
All, I wasn't paying attention and uploaded the wp-config.php to my wordpress site. I
Thanks for the help on here with my query on here the other day
Thanks for stopping by. this static analyser warning is annoying me here is my
Thanks to the epic work of Dennis Williamson, I am now able to calculate
Thanks for your attention and time. I need your opinion on an basic architectural
Newb RoR developer here, standing at the finish line of my first paying Rails
Do screen readers just read content without paying attention to CSS? My reason for
I'm trying to achieve this effect with jQuery. I wrote some of the code,
Thanks for reading this. I have no idea why this is throwing a NullReferenceException

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.