I am using jQuery selector to return objects.
For example, var target = $('.target'); will return 6 objects.
Objects do not have the same parent.
I want to give each class of objects like this:
target[0].addClass('top'); target[1].addClass('middle'); target[2].addClass('low'); target[3].addClass('top'); target[4].addClass('middle'); target[5].addClass('low');
And so on ... I thought I could use some module. I know what is wrong.
target.each(function(index){ index += 1; if (index % 3 === 0) { $(this).addClass('low'); } else if(index % 2 === 0) { $(this).addClass('middle'); } else { $(this).addClass('top'); } }
Is there an easy way that I look?
source share