If you want to set a class, a cheaper way to do this is .attr()with an index in its setter function, like this:
$("ul li").attr("class", function(i) {
return "cat" + (i+1);
});
If you do not install it and just add , use .addClass(function(i)instead .attr("class", function(i).
source
share