Lego2012
12/13/2016 - 2:49 PM

Assign even and odd classes using jQuery

Assign even and odd classes using jQuery

/* CSS method: */

.front-page-5 .featured-content .entry:nth-child(odd) a.alignnone {
	float: right;
}

.front-page-5 .featured-content .entry:nth-child(even) a.alignnone {
	float: left;
}
$( '.front-page-5 .entry' ).each(function(i, el) {
        // As a side note, this === el.
        if ( i % 2 === 0 ) {
            /* we are even */
            $(el).addClass( 'even' );
        }
        else {
            /* we are odd */
            $(el).addClass( 'odd' );
        }
    });