Is this what you want?
LIVE DEMO Depending on the 0f index, the hover changes color according to the position of the array:
var dlC = [ 'rgb(233, 147, 26)', 'rgb(22, 145, 190)', 'rgb(22, 107, 162)', 'rgb(27, 54, 71)' ]; var dlH= [ '#000', 'rgb(22, 145, 190)', 'rgb(22, 107, 162)', 'rgb(27, 54, 71)' ]; $('.abc').each(function( i ) { $(this).css({backgroundColor : dlC[i] }) .on("mouseenter mouseleave",function( e ) { $(this).css({backgroundColor : e.type=="mouseenter" ? dlH[i] : dlC[i] }); }); });
the ? : ? : I used the ternary operator. You can use Goog for it if you do not know how logic works.
source share