Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Richard Feinburg
2,970 Pointsonclick and disable after the next onclik
I'm trying to set a onclick for a svg when they click on an object the color change but when they click on a different part of the svg, the last onclick would go back to the original state before the onclick. Here is my code. I know there is no offclick!
for(var state in map){
(function(st, state){
st[0].onclick = function (){
st.toFront();
$('#whichState').html(getStateName(state));
st.stop().animate({stroke: "#fff", 'stroke-opacity': '4', "fill-opacity": "1"}, 300);
};
st[0].offclick = function (){
$('#whichState').html("");
st.animate({stroke: "#fff", "fill-opacity": ".7"}, 300);
}
})(map[state], state);
}
1 Answer

Jacob Fetner
5,518 PointsMaybe you could have a variable that holds a function that will set the last clicked item back to its original state. See this simple example. In the example if you click on red div it will change to blue. Then if you click on the green div it will change to yellow, but it will also change the blue div back to its original red state.