Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery: how to hide tables depending on text input
    primarykey
    data
    text
    <p>I have one text input box</p> <pre><code>&lt;input type="text" id="search" /&gt; </code></pre> <p>and <strong>multiple HTML-tables</strong> like this: </p> <pre><code>&lt;table id="table1"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Table1 title&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Country&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Andrew&lt;/td&gt; &lt;td&gt;USA&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;John&lt;/td&gt; &lt;td&gt;Canada&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>I want to filter data depending on what user types in the input box.</p> <p>Now my JS code is:</p> <pre><code>$(document).ready(function(){ $("#search").keyup(function(){ // When value of the input is not blank if( $(this).val() != "") { // Show only matching TR, hide rest of them $("#table1 &gt; tbody &gt; tr").hide(); $("#table1 td:contains-ci('" + $(this).val() + "')").parent("tr").show(); } else { // When there is no input or clean again, show everything back $("#table1 tbody &gt; tr").show(); } }); }); // jQuery expression for case-insensitive filter $.extend($.expr[":"], { "contains-ci": function(elem, i, match, array) { return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) &gt;= 0; } }); </code></pre> <p>Everything works OK.</p> <p>But now I want to hide a whole table including thead TR's if a typed text is not in the table.</p> <p>How can I get that?</p>
    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.
 

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