I downloaded a world map SVG to mess around with SVG manipulation with Javascript. My goal is to change the color of the United States when I click on it, and then when I click on it again it goes back to the original color. Here is the part of the SVG that defines the United States:
<path
inkscape:connector-curvature="0"
id="US"
data-name="United States"
data-id="US"
d="m 116.7,450.7 2,-0.9 2.5,-1.4 0.2,-0.4 -0.9,-2.2 -0.7,-0.8
-7.1,-0.5 -6.2,-1.6 -4.8,0.5 -4.9,-0.9 2,-1.2 -6.3,-0.3 -3.3,1
0.5,-2.4 z"
style="fill:#f2f2f2;fill-rule:evenodd" />
(I deleted a lot of the coordinates because they were making the code so long)
Here is the CSS:
.united_states {
fill: blue;
}
Here is the javascript, using JQuery:
$(function(){
$('#US').click(function(event){
console.log("You just clicked on the United States!!");
$('#US').toggle();
$(this).toggleClass('.united_states');
});
})();
And finally, here is a JsFiddle of it: link
Changing the 'fill' attribute of the tag to blue worked, but I want to do it on click, and toggle it (blue and then back to normal).
Thank you for your help.