I am currently working with a loop on an array of nodes in my project. One of the requirements is to display the name of each node as a tooltip for specific Raphael elements on the screen.
Below is a snippet of the code I have written so far:
for(var i=0; i<nodes.length; i++){
paper.rect(nodes[i].getX(), nodes[i].getY(), nodes[i].width, nodes[i].getHeight())
.attr({fill:nodes[i].getColor(), "fill-opacity": 1}).mouseover(function () {
this.animate({"fill-opacity": .4}, 500);
this.attr({title:nodes[i].name});
}).mouseout(function () {
this.animate({"fill-opacity": 1}, 500);
}).drag(move, dragstart, dragend);
}
However, I encountered an issue where the nodes[i] in the .mouseover function is returning undefined. The question arises, why is this happening? Is there any way to pass it like .mouseover(nodes[i]) to the function and then how can we utilize it?