This is best explained with a Fiddle: http://jsfiddle.net/hxsJx/
I want to add a class to the nth-children of an element, but only when those children have a particular class. So in my example, only articles E and J should get the class of ‘end’.
The nth-child selector seems to be ignoring the class selector, which is probably intended behaviour, but I just can’t find a way around it.
Thanks for any pointers folks…
The selector is working as intended. Remember, the CSS
:nth-childselector is one-based (it starts counting at one).The
4nth elements areDandH, which indeed have class1.Your selector:
.articles article.1:nth-child(4n)HTML: