Take a look at this example:
var contador = 0;
$('div').each(function() {
if ($(this).hasClass('box')) {
contador++;
this.innerHTML = contador;
if (contador % 2 == 0) this.style.color = 'blue'; // ou outro código que precises
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divclass="box"></div>
<div class="box"></div>
<div class="box"></div>
<div>Eu não tenho a classe box</div>
<div>Eu não tenho a classe box</div>
<div class="box"></div>
This code only counts the elements that have the class you want and using % 2 == 0
you know when the count has zero rest divided by 2.
If you want to "go two-by-two" you can do this too:
$('.box:nth-of-type(2n)').each(function(i) {
this.style.color = 'blue'; // ou outro código que precises
});
jsFiddle: link
If you want to do things with CSS, it's best to use nth-of-type(2n)
. But that was not clear from your question.