Hey Adam,
Glad you found that! :-) Klaus's version is a lot simpler, though,
so you might want to try that instead. At press time, the :nth-child
() didn't allow for something like :nth-child(3n) or :nth-child(3n
+2); it just took a single number, like :nth-child(3). It's much more
robust now.
Cheers,
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Oct 1, 2007, at 6:24 PM, Adam Stacoviak wrote:
I figured it out...I just needed to do a bit more reading to my
Learning jQuery book!
var classNames = {
0: 'first',
1: 'second',
2: 'third'
};
$('#section_wrapper_div .section_item').each(function(index) {
$(this).addClass(classNames[index % 3]);
});
On 10/1/07, Adam Stacoviak <[EMAIL PROTECTED]> wrote:
I'm trying to find out how to add a class to every third occurrence of
an element.
Basically, I have a DIV with an undefined number of DIVs inside of it,
and I want to add a class to every third DIV.
Thanks!