javascript - Adding a class to an array of elements with forEach not working? -


i converted node list returned queryselector() method array still can't foreach work (i want add class). can tell me i'm doing wrong?

my code extremely simple i'm new js.

this html:

<table>     <tr>         <th>this th</th>         <th>this th</th>         <th>target</th>         <th style="display: none;"></th>     </tr>     <tr>         <td>this table cell</td>         <td>this 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());   })(); 

your argument order wrong . should work

(function(){      "use strict";      var th = array.prototype.slice.call(document.queryselectorall("th")),         td = array.prototype.slice.call(document.queryselectorall("td"));      function test(el, index, array) {         el.classname = "color";     }      th.foreach(test);   })(); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -