Using jQuery, is it possible to assign a class to an object based on its index?
For example, if I have an ul with five list items, how would I assign the class "0" to the first item, "1" to the second item, "2" to the third, item and so on?
This was my first attempt:
$('ul.nav li').each(function(index){
$(this).addClass(index);
});