Add Class to Every Other Item in List
Permalink
I need to add a class to every other LI tag in a list, so it is applied to even numbered items only. Below is the code I have now for displaying each item.
How do I make it so that a class is added to every other item (all even numbers)?
How do I make it so that a class is added to every other item (all even numbers)?
Have you css and the ':nth-child'?
That occurred to me, but it won't work due to the nature of the block I'm working on. Basically, the resulting code will be something like this:
<ol> <li>Item 1</li> <li class="fluffynuggins">Item 2</li> <li>Item 3</li> <li class="fluffynuggins">Item 4</li> <li>Item 5</li> ... </ol>
Ok, looks like I found a simple solution using CSS.
I did this:
That works just fine as it applies the styles to all even-numbered items.
I did this:
ol li:nth-of-type(2n) { styles... }
That works just fine as it applies the styles to all even-numbered items.