David Craig
David Craig

Reputation: 164

Custom JavaScript - Not working in chrome

I have some custom javascript code which works great in firefox, however in chrome it seems to not respond at all, the page is located here: http://wiki.tf2clan.co.uk/index.php/games/sizes

I would appreciate any input as to why chrome doesn't like this, and/or any alternative code snippets

Upvotes: 0

Views: 1829

Answers (2)

Tomas Ramirez Sarduy
Tomas Ramirez Sarduy

Reputation: 17471

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();

Upvotes: 2

mohammad mohsenipur
mohammad mohsenipur

Reputation: 3149

see chrome developer tools for Errors ctrl+shift+j

Upvotes: 1

Related Questions