Good day!
How can I hide all the rows in a checkbox with columns containing only zeros?
For the time being, I come up with a variant in which all empty lines have a class < tr class="zero"> and with the help of js I change the style , but the whole table floats - the cells become different widths.
Initially I create the table myself, so it is possible to set classes and styles.
//js файл function toggle() { var rows = document.getElementsByClassName('zero'); for (var i = 0; i < rows.length; i++) { if (this.checked) rows[i].style.display = 'block'; else rows[i].style.display = 'none' } } document.getElementById('chkTest').onchange = toggle; <input type="checkbox" id="chkTest" /> <label for="chkTest">Hide all zero rows</label> <table> <tr class="zero"> <td>Ivanov</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> </tr> <tr> <td>Petrov</td> <td>1</td> <td>2</td> <td>0</td> <td>9</td> <td>8</td> <td>0</td> </tr> <tr class="zero"> <td>Sidorov</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> </tr> <tr class="zero"> <td>Morozov</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> </tr> <tr> <td>Tosterov</td> <td>2</td> <td>1</td> <td>5</td> <td>0</td> <td>0</td> <td>1</td> </tr> </table> Found this method in the Internet. He just started learning JS.
PS All options are interested, but please highlight how to do it and which methods work faster.
The table is approximate, in fact the table contains hundreds of rows.
Thank you in advance.
rows[i].style.display = 'block';the rows of the table must be set todisplay: table-row;- Grundyzeroclass set? - C.Raf.T