PDA

View Full Version : Zebra: (un)ordered lists



Compugasm
7 Nov 2006, 5:20 PM
There is code for making zebra tables, but is there zebra lists?

<pre><code>
function zebraList(id){
var even = false;
var evenColor = arguments[1] ? arguments[1] : "#FFFFFF";
var oddColor = arguments[2] ? arguments[2] : "#DDD";
// obtain a reference to the desired list
// if no such list exists, abort
var ul = document.getElementById(id);
if (! ul) { return; }
var lis = ul.getElementsByTagName("li");
// and iterate through them...
for (var h = 0; h < lis.length; h++) {
var list = lis[h];
list.style.backgroundColor = even ? evenColor : oddColor;
// flip from odd to even, or vice-versa
even = ! even;
}
}
</code></pre>

Compugasm
7 Nov 2006, 6:33 PM
Oh duh. There is zebra color in the grid control. Nevermind.

jack.slocum
7 Nov 2006, 7:00 PM
You could do soemthing like this:

getEls("ul li:nth-child(odd)").addClass('odd');