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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:12:01+00:00 2026-06-09T01:12:01+00:00

I have this simple function which toggles a hidden element in the webpage. function

  • 0

I have this simple function which toggles a hidden element in the webpage.

function showtable(id) 
 {
 if(document.getElementById(id).style.display == 'block')
  {
document.getElementById(id).style.display = 'none';
  }else{
document.getElementById(id).style.display = 'block';
}
 } 


<input type="button" value="Toggle" onclick="showtable('id');" />

This works fine, but I want to toggle off some other (table) element (with certain ids) (except for the one which is being toggled, whether on or off) on the page every time the button is clicked.

  • 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-09T01:12:03+00:00Added an answer on June 9, 2026 at 1:12 am

    You could use jQuery, but if you don’t want to use that; here is a pure javascript example. To see how it works, copy paste it in a text file, save it as test.htm and open it in a browser. It contains three tables, each with a button above it. When clicking a button, it’s table gets displayed and all other tables get hidden. If you need more tables, give them an id, and add their id to the array in the function:

    var ids = ["redTable", "greenTable", "blackTable", "anotherTable"]; 
    

    If you want to be able to toggle that table also, it will off course also need a button:

    <input type="button" value="Toggle Green Table" onclick="showtable('anotherTable');" />
    

    example:

    <!DOCTYPE html>
    <html>
        <head>
            <script type="text/javascript">
                function showtable(id) {
                    var ids = ["redTable", "greenTable", "blackTable"];
                    for(var i = 0; i < ids.length; i++) {
                        if(ids[i] != id)
                            document.getElementById(ids[i]).style.display = "none";
                    }
                    document.getElementById(id).style.display = "block";
                }
            </script>
        </head>
        <body>
            <input type="button" value="Toggle Red Table" onclick="showtable('redTable');" /><br />
            <table style="width: 100px; height: 100px; background-color: red;" id="redTable">
                <tr>
                    <td>redTable</td>
                </tr>
            </table>
            <input type="button" value="Toggle Green Table" onclick="showtable('greenTable');" /><br />
            <table style="width: 100px; height: 100px; background-color: green; display: none;" id="greenTable">
                <tr>
                    <td>greenTable</td>
                </tr>
            </table>
            <input type="button" value="Toggle Black Table" onclick="showtable('blackTable');" /><br />
            <table style="width: 100px; height: 100px; background-color: black; display: none;" id="blackTable">
                <tr>
                    <td>blackTable</td>
                </tr>
            </table>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I have this simple function which I pass in an array of strings: function
I have this simple javascript function which changes the body zoom of the web
I have a simple function which disables/enables select element when checkbox is checked/unchecked. It
There is this simple function which I have used with C++ in the past
I have this simple function: <script type=text/javascript> //<![CDATA[ jQuery(function($){ function here(b){alert(b);} ; here(6); });
I have this very simple jQuery function: $(.milestone-in-tree).live({ mouseenter: function() { setTimeout( $.ajax({ type:
I have this very simple br2nl function that I use to take a string
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
So, I have this simple code $('#info_name'+index).show(slide, {direction: right}, 1000, function(){ $('#info_info'+index).show('slide',{direction: up}, 1000);

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.