Take a look at this fiddle , I think it does what you are looking for. The main difference is that you want to name the animation on the set, not this . It seems that when you add a handler to the set, this refers to the individual elements in the set (which iterations are assigned to the handler), and not to the set itself.
Note that I pulled the handler functions into the getHoverHandler function:
function getHoverHandler(fillColor) { var cSet = set; return function(){ cSet.animate({fill: fillColor}, 300); }; } set.hover(getHoverHandler('#000'), getHoverHandler('#FFF'));
to break the circuit. If you try to do it like this:
set.hover(function(){ set.animate({fill: '#000'}, 300) }, function(){ set.animate({fill: '#FFF'}, 300) });
when you go through the loop, the set will continue to change, and closing will maintain an understanding of this. As a result, all handlers will act on the last line of the boxes.
If you do not understand javascript closure, you can see this article. This is an old but fairly simple language, and it helped me when I tried to circle around me.
source share