I converted a node list returned by the querySelector() method to an array but I still can't get forEach to work (I just want to add a class). Can someone tell me what I'm doing wrong?
My code is extremely simple as I'm very new to JS.
This is the HTML:
<table>
<tr>
<th>This is a th</th>
<th>This is a th</th>
<th>Target</th>
<th style="display: none;"></th>
</tr>
<tr>
<td>This is a table cell</td>
<td>This is a table cell</td>
<td>Target</td>
<td style="display: none;"></td>
</tr>
</table>
JS:
(function(){
"use strict";
var th = Array.prototype.slice.call(document.querySelectorAll("th")),
td = Array.prototype.slice.call(document.querySelectorAll("td"));
function test(index, el, array) {
el.className = "color";
}
th.forEach(test());
})();