I'm trying to create a filter feature that removes certain scores from a table based on min and max value.
My HTML:
<table id="historyTable">
<tr>
<th>Game #</th>
<th>Date</th>
<th>Location</th>
<th>Score</th>
<th>Strikes</th>
<th>Spares</th>
</tr>
<tr>
<td>299</td>
<td>29 Feb 2016</td>
<td>Hello World Bowling Alley</td>
<td>202</td>
<td>6</td>
<td>1</td>
</tr>
<tr> ...same thing as above repeated a few times </tr>
</table>
I've got a button that takes the user's input min and max values and passes it to the following JS function onclick:
function updateFilter(min, max) {
var table = document.getElementById('historyTable');
var rowCount = table.rows.length-1; // since I don't want to include the header row
for(var i = 1; i<=rowCount; i++) {
var scoreCheck = table.rows[i].cells[3].innerHTML;
if(scoreCheck < min || scoreCheck > max) {
$(table.rows[i].innerHTML).hide();
}
}
}
However, it doesn't seem to be working. What am I doing wrong?
$(table.rows[i].innerHTML)is wrong – when you pass HTML code (which is what .innerHTML returns) to $(), it will create new HTML elements out of it. You want to hide the table row, so$(table.rows[i]).hide()(Although that is a rather crude mix of “vanilla” JavaScript and jQuery you have there … why not use jQuery “all the way”, if you are using it already?)