html table column hide


I have a html table with 5 columns and a header column for each column. I want to use 5 checkboxes to hide/unhide columns using jquery, javascript or css, any idea?

the best efficient method that you can suggest, thank you!!!!!!!!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, here's a JSFiddle you can look at that does exactly what you're looking for.
Alexandre SimõesManager / Technology SpecialistCommented:
Here's a quick solution without having to decorate every td with a colIdx class:
<table id="myTable" width="100%" border="1">
            <td>Column 1</td>
            <td>Column 2</td>
            <td>Column 3</td>
            <td>Column 4</td>
            <td>Column 5</td>
            <td>Value 1.1</td>
            <td>Value 1.2</td>
            <td>Value 1.3</td>
            <td>Value 1.4</td>
            <td>Value 1.5</td>
            <td>Value 2.1</td>
            <td>Value 2.2</td>
            <td>Value 2.3</td>
            <td>Value 2.4</td>
            <td>Value 2.5</td>

<input id="chk1" type="checkbox" onchange="toggleColumn(1);" />
<label for="chk1">Toggle column 1</label>
<input id="chk2" type="checkbox" onchange="toggleColumn(2);" />
<label for="chk2">Toggle column 2</label>
<input id="chk3" type="checkbox" onchange="toggleColumn(3);" />
<label for="chk3">Toggle column 3</label>
<input id="chk4" type="checkbox" onchange="toggleColumn(4);" />
<label for="chk4">Toggle column 4</label>
<input id="chk5" type="checkbox" onchange="toggleColumn(5);" />
<label for="chk5">Toggle column 5</label>

Open in new window

function toggleColumn(colPos){
    $('#myTable tr').each(function(idx,item){

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.