Juuro
Juuro

Reputation: 227

DOM-modification in Safari Extension

I try to code a Safari Extension which visualizes some data on a website with tables. So, to compute the data I do a little JavaScript:

var table;
table = document.body.getElementsByClassName('summary');
console.log(table);

var rows = table.getElementsByTagName('tr');
console.log(rows);

The second row works fine, but for the fifth row I get this error:

TypeError: 'undefined' is not a function (evaluating 'table.getElementsByTagName('tr')')

Why is that? Whith this code:

document.body.getElementsByClassName('summary').getElementsByTagName('tr');

it's the same.

Whats my mistake?

Upvotes: 0

Views: 427

Answers (1)

anton_byrna
anton_byrna

Reputation: 2555

getElementsByClassName this method return you array so you need to pick table from this array: var rows = table[0].getElementsByTagName('tr'); if first found table is what you need but it seems that no tables are found in second line.

Upvotes: 3

Related Questions