Skip to content

Instantly share code, notes, and snippets.

@AdamTReineke
Created July 26, 2011 16:42
Show Gist options
  • Save AdamTReineke/1107198 to your computer and use it in GitHub Desktop.
Save AdamTReineke/1107198 to your computer and use it in GitHub Desktop.
Color the rows of an HTML table with alternating classes, row and altRow. (jQuery)
/**
* Color the table rows by adding row and altRow classes to the table.
* Note: ignores any table rows with the class hidden.
* @param id The id of the table
*/
function colorTableRows(id) {
var rows = $("table#" + id + " > tbody > tr").not("tr.hidden").removeClass("altRow row");
rows.filter(":odd").addClass("altRow");
rows.filter(":even").addClass("row");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment