How to count total visible rows in html table using javascript, I have a code below that filters table rows while typing, I would like to see the number count of visible rows displayed in an innerHTML whole typing automatically
i tried this line of code but i dont see any results in the innerHTML
document.getElementById("statistic").innerHTML = tr[i].length;
FULL CODE
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("MyTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1]; // change number to any other number to target column for table search
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
document.getElementById("statistic").innerHTML = tr[i].length;
} else {
tr[i].style.display = "none";
}
}
}
2
Answers
something like that ?