I'm creating dynamically canvas elements with Raphael.js, but I need change the color when the element is pressed. I just attach the click event over each specific circle, but How I can change the color of the pressed element?
paper = Raphael("canvas", 500, 500);
circs = paper.set();
for (i = 0; i < 21; ++i)
{
opa = ran(3,10)/10;
circs.push(paper.circle(ran(0,500), ran(0,500), ran(13,30)).attr({"fill-opacity": opa,
"stroke-opacity": opa }).click(function(){
$("#toggle").click();
//Change color?
}));
}
Not quite sure what the toggle is there, may help if you produce a jsfiddle if needed.
Typically you would do something like
paper.circle(x,y,r).click(function(){
this.attr({ fill: "blue", opacity: "0.5" });
});