JSFiddle - React, Tailwind, and code Playground

HTML

<p class="class">The first paragraph.</p>
<p>The second paragraph.</p>
<p class="class">The third paragraph.</p>
<p class="class">The fourth paragraph.</p>

CSS

p.class.even {
    background: #ff0000 ;
}

p.class.odd {
    background: green ;
}

JavaScript

$(document).ready(function () {
    $('.class').each(function(i){
        if (i % 2 == 0) {
            $(this).addClass('even');
        } else  {
            $(this).addClass('odd');
        }
    });
})