I have some HTML that looks like this:
<div class="primary-billing">
<div>1</div>
<div>4</div>
<div>3</div>
<div>10</div>
<div>5</div>
<div>5</div>
<div>4</div>
<div>3</div>
<div>10</div>
<div>5</div>
<div>5</div>
</div>
And I want to group the elements in groups of two so that I can set each groups background to a different color, right now I am doing it like this:
.primary-billing div:nth-child(n+1):nth-child(-n+2){
background: yellow;
}
.primary-billing div:nth-child(n+3):nth-child(-n+4){
background: blue;
}
.primary-billing div:nth-child(n+5):nth-child(-n+6){
background: purple;
}
But as in my actual code it is much longer and there must be a better way, I'm also trying to do it in Javascript where I could have an array of the colors I wanted, but still am not sure how to group the element in groups of 2. Here is a JSBin with the code JSBin
How could I get them in groups of two using Javascript or CSS?