Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following is building on Eran's code, with a few minor changes. Tested it and it seems to work fine on Firefox 3, IE7.</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;script&gt; $(document).ready(function() { $('input[type="checkbox"]').click(function() { var index = $(this).attr('name').substr(3); index--; $('table tr').each(function() { $('td:eq(' + index + ')',this).toggle(); }); $('th.' + $(this).attr('name')).toggle(); }); }); &lt;/script&gt; &lt;body&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class="col1"&gt;Header 1&lt;/th&gt; &lt;th class="col2"&gt;Header 2&lt;/th&gt; &lt;th class="col3"&gt;Header 3&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tr&gt;&lt;td&gt;Column1&lt;/td&gt;&lt;td&gt;Column2&lt;/td&gt;&lt;td&gt;Column3&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Column1&lt;/td&gt;&lt;td&gt;Column2&lt;/td&gt;&lt;td&gt;Column3&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Column1&lt;/td&gt;&lt;td&gt;Column2&lt;/td&gt;&lt;td&gt;Column3&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Column1&lt;/td&gt;&lt;td&gt;Column2&lt;/td&gt;&lt;td&gt;Column3&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;form&gt; &lt;input type="checkbox" name="col1" checked="checked" /&gt; Hide/Show Column 1 &lt;br /&gt; &lt;input type="checkbox" name="col2" checked="checked" /&gt; Hide/Show Column 2 &lt;br /&gt; &lt;input type="checkbox" name="col3" checked="checked" /&gt; Hide/Show Column 3 &lt;br /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload