Jquery modify elements in each loop
问题 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? 回答1: use .each() method instead and you have to be in the context with $