javascript - alternating table row backcolor without jQuery -
javascript - alternating table row backcolor without jQuery -
suppose table :
<table> <tr><td>aaaaaaaa</td><td>nnnnnnnnnn</td></tr> <tr><td>aaaaaaaa</td><td>nnnnnnnnnn</td></tr> <tr><td>aaaaaaaa</td><td>nnnnnnnnnn</td></tr> <tr><td>aaaaaaaa</td><td>nnnnnnnnnn</td></tr> <tr><td>aaaaaaaa</td><td>nnnnnnnnnn</td></tr> </table> with css:
<style> .even{background:red;} </style> how can write pure js code adds class tr's of table ? [no jquery]
if need style reasons, can utilize css3 selectors (no javascript needed):
tr:nth-child(odd) { background-color: red; } tr:nth-child(even) { background-color: green; } javascript jquery html css
Comments
Post a Comment