Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript AddClass “1” to “6” then repeat after six list items jQuery Re: AddClass “1” to “6” then repeat after six list items jQuery

#84337
Mottie
Member

Here is another version of Johnnyb’s code (demo):

$('ul').find('li').each(function(i){
var num = (i%6) + 1; // mod function - returns the remainder
$(this)
.addClass('class-' + num )
.html('item ' + num);
});