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

The Archive Base Latest Questions

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

I have some tables here, and using this javascript below, I made them hide

  • 0

I have some tables here, and using this javascript below, I made them hide and show every time a user click on their buttons. What I want to add in to this script, is when someone click on a table’s button to show-up, all the other to be hidden. Any idea how can I do this? Thank you in advance!

This is my html code:

<table id="SC1_TH_" class="header_op"><tr><td>
<div id="SC1_BSH_" onClick="SC[1]();" class="hide_button">*</div>OPTION ONE
</td></tr></table>
<div id="SC1_BO_" style="display:dlock;">BLAH BLAH</div>

<table id="SC2_TH_" class="header_cl"><tr><td>
<div id="SC2_BSH_" onClick="SC[2]();" class="show_button">*</div>OPTION ONE
</td></tr></table>
<div id="SC2_BO_" style="display:none;">BLAH BLAH</div>

<table id="SC3_TH_" class="header_cl"><tr><td>
<div id="SC3_BSH_" onClick="SC[3]();" class="show_button">*</div>OPTION ONE
</td></tr></table>
<div id="SC3_BO_" style="display:none;">BLAH BLAH</div>

This is my javascript:

<script type="text/javascript">

var SC = [];

for (var i = 1; i < 10; i++) {

SC[i] = (function(i){

return function(){

var SC_TH  = document.getElementById('SC'+i+'_TH_');
var SC_BSH = document.getElementById('SC'+i+'_BSH_');    
var SC_BO  = document.getElementById('SC'+i+'_BO_');

  if (SC_BO.style.display == 'block' || SC_BO.style.display == ''){
      SC_TH.className      = 'header_cl';
      SC_BSH.className     = 'show_button';
      SC_BO.style.display  = 'none';}
else {SC_TH.className      = 'header_op';
      SC_BSH.className     = 'hide_button';
      SC_BO.style.display  = 'block';}
     }})(i);}       
</script>

EDIT: In other words, I need something to say, if this button that clicking right now is something all the other to be hidden!!!

  • 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-17T12:10:08+00:00Added an answer on June 17, 2026 at 12:10 pm

    Here’s a working example with some very simple jQuery (recommended) code.

    HTML:

    <table><tr><td>
    <div class="toggle-button">*</div>OPTION ONE
    </td></tr></table>
    <div class="toggle">BLAH BLAH</div>
    
    <table><tr><td>
    <div class="toggle-button">*</div>OPTION ONE
    </td></tr></table>
    <div class="toggle">BLAH BLAH</div>
    
    <table><tr><td>
    <div class="toggle-button">*</div>OPTION ONE
    </td></tr></table>
    <div class="toggle">BLAH BLAH</div>
    

    JS:

    $(function() {
        $('div.toggle').hide();
        $('.toggle-button').click(function(){
            $('div.toggle').hide();
            $(this).closest('table').next('div.toggle').show();
        });
    });
    

    As @StephenByrne mentioned, I also strongly recommend using an existing component such as jQuery Accordian. It takes minutes to implement and comes with a whole host of themes to chose from and is fully customisable. You could spend hours or days writing your own. Unless it’s a learning exercise, it’s simply a waste of time. No need to reinvent the wheel.

    As you have indicated a strong push towards js-only, here’s a working js-only solution.

    HTML:

    <table id="SC1_TH_" class="header_op"><tr><td>
    <div id="SC1_BSH_" onclick="toggle(this);" class="hide_button">*</div>OPTION ONE
    </td></tr></table>
    <div id="SC1_BO_" style="display:block;">BLAH BLAH</div>
    
    <table id="SC2_TH_" class="header_cl"><tr><td>
    <div id="SC2_BSH_" onclick="toggle(this);" class="show_button">*</div>OPTION ONE
    </td></tr></table>
    <div id="SC2_BO_" style="display:none;">BLAH BLAH</div>
    
    <table id="SC3_TH_" class="header_cl"><tr><td>
    <div id="SC3_BSH_" onclick="toggle(this);" class="show_button">*</div>OPTION ONE
    </td></tr></table>
    <div id="SC3_BO_" style="display:none;">BLAH BLAH</div>
    

    JS:

    function toggle(src) {
        var id =  src.id;
        var index = id.substring(2, 3);
    
        var i = 1;
        var toggleItem = document.getElementById('SC' + i.toString() + '_BO_');
    
        while (toggleItem != null) {
            var bShow = index == i;
            var button = document.getElementById('SC' + i.toString() + '_BSH_');
            var table = document.getElementById('SC' + i.toString() + '_TH_');
    
            if (bShow) {
                toggleItem.style.display = 'block';
                toggleItem.className = 'setitemclassname';
                button.className = 'setbuttonclassname';
                table.className = 'settableclassname';
            }
            else {
                toggleItem.style.display = 'none';
                toggleItem.className = 'setitemclassname';
                button.className = 'setbuttonclassname';
                table.className = 'settableclassname';
            }
            toggleItem = document.getElementById('SC' + (++i).toString() + '_BO_');
        }
    }
    

    Inside the while loop when index == i evaluates to true, you know you have the item to show. Add extra logic there to change your class names.

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

Sidebar

Related Questions

Using this as a simplified example, assume I have a table that has some
I have some javascript I would like to execute only if a user is
Trying to have my PHP script return some SQL table queries. Here's my script
I have a table in sql 2008 named tblEmployeeAttendance like Here is some dummy
I have a table with three fields, FirstName, LastName and Email. Here's some dummy
I have some tables roughly like so: Client: id name Employee id name Email
I have some tables that I'm joining in a query with Postgres (9). However,
I have some tables with data: Category CategoryID CategoryName 1 Home 2 Contact 3
I have some tables that benefit from many-to-many tables. For example the team table.
I have some tables. These tables all have one column in common called 'classified_id':

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.