In addition to the explanation, what does the $ mean in javascript? Here is the code:
var ZebraTable = { bgcolor: '', classname: '', stripe: function(el) { if (!$(el)) return; var rows = $(el).getElementsByTagName('tr'); for (var i=1,len=rows.length;i<len;i++) { if (i % 2 == 0) rows[i].className = 'alt'; Event.add(rows[i],'mouseover',function() { ZebraTable.mouseover(this); }); Event.add(rows[i],'mouseout',function() { ZebraTable.mouseout(this); }); } }, mouseover: function(row) { this.bgcolor = row.style.backgroundColor; this.classname = row.className; addClassName(row,'over'); }, mouseout: function(row) { removeClassName(row,'over'); addClassName(row,this.classname); row.style.backgroundColor = this.bgcolor; } } window.onload = function() { ZebraTable.stripe('mytable'); }
Here is a link to where I got the code and you can view a demo on the page. It does not appear to be using any framework. I was actually going through a JQuery tutorial that took this code and used JQuery on it to do the table striping. Here is the link:
http://v3.thewatchmakerproject.com/journal/309/stripe-your-tables-the-oo-way
1 Answer