Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best way is to wrap your headers in <code>&lt;thead&gt;</code> and your rows in <code>&lt;tbody&gt;</code>, then you can use this code:</p> <pre><code>$myTable = $("#myTable"); $("thead &gt; tr", $myTable).click(function() { $("tbody &gt; tr", $myTable).fadeOut(); }); </code></pre> <p>But if you dont want to use them, this code will work (assuming only the first row is your header row):</p> <pre><code>$myTable2 = $("#myTable2"); $("tr:eq(0)", $myTable2).click(function() { $("tr:gt(0)", $myTable2).fadeOut(); }); </code></pre> <p><strong>Examples:</strong> <a href="http://jsfiddle.net/Wxa3W/1/" rel="nofollow">http://jsfiddle.net/Wxa3W/1/</a></p> <h2>Edit:</h2> <p>Updated answer to your updated question.</p> <p><strong>Html:</strong></p> <pre><code>&lt;table class="MyTable"&gt; &lt;thead&gt; &lt;tr&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p><strong>JavaScript:</strong></p> <pre><code>$(function() { $(".MyTable &gt; thead &gt; tr").click(function() { $(this).closest(".MyTable").find("tbody &gt; tr").fadeOut(); }); }); </code></pre> <p>And if you don't want thead/tbody:</p> <p><strong>Html:</strong></p> <pre><code>&lt;table class="myTable"&gt; &lt;tr class="myHeader"&gt;&lt;th&gt;Header 1&lt;/th&gt;&lt;th&gt;Header 2&lt;/th&gt;&lt;th&gt;Header 3&lt;/th&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;td&gt;Data&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; </code></pre> <p><strong>JavaScript:</strong></p> <pre><code>$(function() { $(".myTable .myHeader").click(function() { $(this).closest(".myTable").find("tr:not(.myHeader)").fadeOut(); }); }); </code></pre> <p><strong>Example:</strong> <a href="http://jsfiddle.net/Wxa3W/2/" rel="nofollow">http://jsfiddle.net/Wxa3W/2/</a></p>
 

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