0

I do have a table of 5 columns.i want to collapse last three columns of the table on click of a image and again reappear on click of other image.I have written some code but its not working so please guide me on this:

<img id="hide" src="assets/img/decrease_indent.png" />
        <img id="show" src="assets/img/increase_indent.png" />

<thead>
                <tr>
                    <th class="">Name</th>
                    <th class=""></th>
                    <th class="">Dur</th>
                    <th class="">Start</th>
                    <th class=""></th>
                </tr>
            </thead>
            <tbody data-bind="foreach:items">
                <tr  data-bind="value:id">
                    <td data-bind="text:"></td>
                    <td></td>
                    <td  data-bind="text:"></td>
                    <td data-bind="text:"></td>
                    <td data-bind="text:"></td>
                </tr>
            </tbody>



    <script type="text/javascript">
$(function(){
        $("#hide").live('click',function(){
        $("th:eq(2),th:eq(3),th:eq(4)td:eq(2),td:eq(3),td:eq(4)").hide();
        });
        $("#show").live('click',function(){
        $("th:eq(2),th:eq(3),th:eq(4)td:eq(2),td:eq(3),td:eq(4)").show();
        });
});
        </script>
Santosh Mishra
  • 108
  • 1
  • 11

2 Answers2

1

Try this,

Live Demo

//To hide
$('th:gt(2)').hide();
$('td:gt(2)').hide();

//To show
$('th:gt(2)').show();
$('td:gt(2)').show();

Edit based on comments

Live Demo

Adil
  • 143,427
  • 25
  • 201
  • 198
0

You miss a comma between th:eq(4) and td:eq(2) in both hide and show.

A working example based on your code can be seen here at jsFiddle.

Note that as you are using .live you cannot use the latest version of jQuery.

Muleskinner
  • 13,657
  • 19
  • 57
  • 78