I'm getting errors on the filter:
Uncaught TypeError: Cannot read property 'innerHTML' of undefined
What I'm doing wrong?
for (i=0;i<50;i++)
{
e = document.getElementsByTagName("tr")[i];
z = e.innerHTML;
}
- You don't know if you will have always 50 elements.
- You are using incorrectly innerHTML
- You are calling
getElementsByTagName in every iteration
Solution:
var nodes = document.getElementsByTagName("tr").childNodes;
//Iterating through TR childs
for(i=0; i<nodes.length; i++) {
alert(nodes[i]);
}
Alternative:
If you are not a Javascript expert, I recommend to use jQuery to manage the DOM elements, it's cross browser and very documented. For example, you could do something like this with jQuery instead the whole for loop:
$('tr > td:not(:contains("+filter_text+")')).hide();
Uncaught TypeError: Object <th>Game</th><th>Version</th><th>Size (GB)</th><th>Last Updated</th> has no method 'contains'