How do I cycle an odd/even class as it loops over the items?

jquery-templates

Solution

Never mind. Overcomplicating things as usual...

Just follow it up with the :odd selector with addClass...

$('#template').tmpl(data).appendTo('#list')
$("#list li:odd").addClass('odd')

Problem

Using the jquery-tmpl, I want to stripe presentation of the rows by adding a class to every second one, so from data ['Cat','Dog','Horse','Noddy'] it generates: ``` <li>Cat</li> <li class="odd">Dog</li> <li>Horse</li> <li class="odd">Noddy</li> ``` The solutions suggested here looked like the start of something that could be further refined for easy digestion by us noddy's.

Original source