Reputation: 43
I am trying to filter a table using javascript to only show rows which have more then 5 seeders. Here is a link to a JSFiddle with an example of the table.
http://jsfiddle.net/xQB4Z/566/
Example of one row:
<td align=left width=500><NOBR><a href="download.php?id=1241487&SSL=1"><img style="position: relative; top: 2px;" src="themes/classic/pic/download.gif.pagespeed.ce.6SI31hDpjb.gif" border="0"></a> <a class="index" href="details.php?id=1241487&hit=1">CENTOS 4</a> (<b><font color="red">NEW!</font></b>)</NOBR><br/><font size=1 color='666666'><i> Uploaded 13 m, 44 seconds after pre</i></font></td>
<td align="right"><b><a href="details.php?id=1241487&hit=1&filelist=1">78</a></b></td>
<td align="right">0</td>
<td align=center><nobr>2016-08-17<br/>23:23:27</nobr></td>
<td align=center>----</td>
<td align=center>6.64<br/>GB</td>
<td align=center>----</td>
<td align="right"><span class="green">2</span></td>
<td align="right"><span class="green">2</span></td>
</tr>
Upvotes: 0
Views: 2182
Reputation: 22474
You can do something like this:
Array.from(document.querySelectorAll("tr")).forEach(function(v, k){
var seeders = v.querySelectorAll("td")[8].textContent;
if(seeders < 5){
v.style.display = "none";
}
});
What this will do is to check the content of 9th column in each row and if the value in this column is smaller then 5, hide the row.
Upvotes: 1
Reputation: 150020
Here's something simple to get you started:
var rows = document.getElementById("yourTableId").querySelectorAll("tr");
for (var i = 1; i < rows.length; i++) { // start at row 1 to skip header
if (+rows[i].cells[8].textContent <= 5)
rows[i].style.display = "none";
}
Demo: http://jsfiddle.net/xQB4Z/568/
Note: I gave your table an id. You could instead use document.querySelector("table")
to just get the first table on the page.
Upvotes: 1