Skip to content
Advertisement

How to hide div that has a table inside if the table’s is empty when filtering using search?

I’m trying to hide the whole div(where there’s a table inside) when the result from filtering/searching thru the table is empty.

So far, I have this:

JavaScript

As you can see, although the table is properly searched, the div and the table that has no value in its <td> is still showing.

How can I hide the whole div if the table’s <td> is empty while searching it?

Advertisement

Answer

Your first problem is that you had several elements with the same ID, e.g. <div id="myTable1div">. I had to give them each a separate ID.

I created a helper function, hideDivs(), which counts the number of rows which are set to display: none, and if there is just one of them (i.e. the header), then hide that corresponding <div>.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement