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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:34:49+00:00 2026-06-04T11:34:49+00:00

After browsing online for tutorials on Javascript show/hide I could only find examples on

  • 0

After browsing online for tutorials on Javascript show/hide I could only find examples on where all the columns were by default visible. I’m looking for a way to have some columns hidden by default (and allow them to be toggled on via a checkbox) and to have some columns shown by default (and allow them to be toggled off via a checkbox).

Is this possible?

For reference my table structure is as follows:

<table>
  <thead>
<tr>
  <th>Name</th>
  <th>Job</th>
</tr>
  </thead>
  <tbody>
    <tr>
      <td>Mike</td>
      <td>Dancer</td>
    </tr>
  </tbody>
</table>
  • 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-04T11:34:50+00:00Added an answer on June 4, 2026 at 11:34 am

    Pure javascript:

    HTML

    <input type="checkbox" onclick="showhide(1, this)" checked="checked" /> Name<br />
    <input type="checkbox" onclick="showhide(3, this)" checked="checked" /> Job<br />
    

    JS

    function showhide(column, elem){
        if (elem.checked)
            dp = "table-cell";
        else
            dp = "none";
        tds = document.getElementsByTagName('tr');
        for (i=0; i<tds.length; i++)
            tds[i].childNodes[column].style.display = dp;
    }
    

    Pure JS fiddle example

    Please consider using a javascript library as JQuery for such trivial things. You code could be as simple as:

    ​
    HTML

    <input type="checkbox" data-col="1" checked="checked" /> Name<br />
    <input type="checkbox" data-col="2" checked="checked" /> Job<br />
    

    jQuery JS:

    $(function(){
        $(':checkbox').on('change', function(){
            $('th, td', 'tr').filter(':nth-child(' + $(this).data('col') + ')').toggle();
        });
    });
    

    jQuery Fiddle example

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

Sidebar

Related Questions

I cant really find my answer after browsing (not a lot of topics on
after browsing the documentation for the sound classes, it seems there is no way
I am interested in using C# to manipulate/Automate Excel files. After browsing the web
I have been trying to get C++11 to work, after browsing different websites and
After googling, browsing SO and reading , there doesn't seem to be a Rails-style
After executing this query on master db ,it is giving me all running process
I logged into an online forum created by using PHP and was browsing some
Using the Google Calendar Api . After browsing the rfc2445 , I'm still unable
Lately I was pointed to http://opencpu.org/ . Nifty website, but after browsing for a
After browsing, I have found that mouse_event(MOUSEEVENTF_WHEEL, 0, 0, 120, 0); is used to

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.