JQuery color every other row in a table

This is so simple and so useful that there is really no excuse to not to have this on your html tables, and it is pretty too 🙂

To change the color of every other row in a table simply add this code to an event that happens after the table has been created:

$("tr:odd").css("background-color", "#bbbbff")

The $(“tr:odd”) selects every tr row with an odd number and the .css() changes its color to #bbbbff – It is as simple as that

Tested on JQuery 1.9.1 and Chrome v28

Comments are closed.

Niklas Tech Blog
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.