/ Published in: JavaScript
A JS function that stripes the tables ("table" elements) of a document. It takes no arguments. Add a new class ("odd") to the odd rows that needs to be styled using CSS. Use addClass function.
From book Dom Scripting by Jeremy Keith.
From book Dom Scripting by Jeremy Keith.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function stripeTables() { if (!document.getElementsByTagName) return false; var tables = document.getElementsByTagName("table"); for (var i=0; i<tables.length; i++) { var odd = false; var rows = tables[i].getElementsByTagName("tr"); for (var j=0; j<rows.length; j++) { if (odd == true) { addClass(rows[j],"odd"); odd = false; } else { odd = true; } } } }