forEach querySelectorAll

by Rich Costello

HTML

<table id="table">
    <tr>
        <td>Foo</td>
    </tr>
    <tr>
        <td>Foo</td>
    </tr>
    <tr>
        <td>Foo</td>
    </tr>
    <tr>
        <td>Foo</td>
    </tr>
    <tr>
        <td>Foo</td>
    </tr>
</table>

CSS

.stripe { background: #ccc; }

JavaScript

var each = Array.prototype.forEach;

var rows = document.querySelectorAll("#table tr");

each.call(rows, function(row, i) {
    if (!(i % 2)) {
        row.className += "stripe";    
    }
});