Using jquery, I want to loop all elements having the class "item" and apply different background colors according to the index of the element.
mapcolor is an array of colors (length = number of elements having "item" class)
$.each($(".item"), function(i,e){
$("#"+e).css("background-color",mapcolor[i]);
});
$("#"+e) selector doesn't work as expected, neither $("#"+e.id) ...
Something's wrong with my selector. Any idea?
$(this).css("background-color",mapcolor[i]);. I think this will work if not please let me know about your HTML DOM structure.$(selector).each()method instead.