I would like to count with javascript the rows with a specific cell content.
This is the HTML code for the table:
<table class="table table-bordered" id="UsersDataTable">
<thead>
<tr>
<th>H0</th>
<th>H1</th>
<th>H2</th>
<th>H3</th>
<th>H4</th>
<th>H5</th>
</tr>
</thead>
<tbody>
<tr>
<td>C0</td>
<td>C1</td>
<td>C2</td>
<td>C3</td>
<td>C4</td>
<td><center><img src=".\pictures\green.jpg" class="img-circle" alt="Green" width="20" height="20"></center></td>
</tr>
</tbody>
</table>
How can I count all cells with 'alt="Green"'?
Until now I have this code snippet:
function CountRows(TableID, alt) {
var refTab = document.getElementById(TableID)
var counter = 0
for ( var i = 0; row = refTab.rows[i]; i++ ) {
alert(refTab.rows[i].cells[5].innerHTML);
if (refTab.rows[i].cells[5].innerHTML === alt)
{
counter ++
}
}
return counter
}
Thanks for help
Patrick