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

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.