How to get colors in order on the divs using arrays
I want these colors to loop in order of colors given. But it gives me only green on all my divs.
You can actually simplify your code and just use the
index from the
.each() method. It’s worth pointing out that the first parameter that is passed in the
.each() method is the
index, and the second is a reference to the current element.
If you have more than three items, you can also use
i % colors.length in order to start back at the beginning of the array after the third index.