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

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -