Ad

How To Hide Every Other Row In A Table?

- 1 answer

I have a typical html table, with tr and td's inside them. How can I use Javascript (Tampermonkey) to hide every other tr?

The tr's don't have specific classes. They only have the tr attribute.

Ad

Answer

Give this a shot:

var rows = document.querySelectorAll('tr:nth-child(odd)'); /* or even */
for(var r = 0; r < rows.length; r++){
    rows[r].style.display = 'none';
}

Basically find all the odd (or even) rows and set their display attribute to none.

Tampermonkey just injects vanilla JavaScript. Nothing special about it.

Ad
source: stackoverflow.com
Ad