Using this Stackoverflow question and the first answer, I was able to convert an SVG image to inline svg on document ready. I can also reference its path' elements from CSS to add a hover stroke.
The next thing I am trying to accomplish is add onclick to each path without having to add it to the svg file itself. I assumed since the CSS can identify each path's class, I should also be able to identify each path's ID in javascript as well, but I am having trouble figuring out how. Here's my code:
<body>
<div id="mapSideBar" class="left">
</div>
<div id="mapMain" class="left">
<img id = "mapImg" src="canada2.svg" class="logo" />
</div>
</body>
I have the function mentioned in the link above to convert it to inline SVG and my paths have ids - path1, path2, path3 and path4. I tried to add the following to the jQuery(document).ready()
function:
var $paths = jQuery(document).find('path');
$paths.each(function() {
(this).click(onImgClick((this).id));
});
just to see if I could get a handle on each path, and I cannot. Is there something I am missing, or is there even a way to assign onclick event handlers to each path?
Thank you, Rishi