Skip to content
Advertisement

Add different class to even and odd divs

I have a block of PHP code that looks like this:

JavaScript

I want the <div> to include a different class based on if it is even or odd. If it is even, it gets X class, if it’s odd it gets Y class.

How do I do this in my case? I’m totally clueless and I don’t know how to start!

Advertisement

Answer

Initialise a variable $count=0; before the loop. Then place the following in the loop: ++$count%2?"odd":"even".

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement