Using this Stackoverflow Question and first answer, I was able to convert the SVG image into an embedded svg into a finished document. I can also reference its path elements from CSS to add a hover stroke.
The next thing I'm trying to accomplish is to add onclick to each path without adding it to the svg file itself. I suggested that since CSS can identify every class of a path, I should also be able to identify every path identifier in javascript, but I find it hard to figure out how to do this. Here is 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 a function mentioned in the link above to convert it to an embedded SVG, and my paths have identifiers - path1, path2, path3 and path4. I tried adding the following to the jQuery(document).ready() function:
var $paths = jQuery(document).find('path'); $paths.each(function() { (this).click(onImgClick((this).id)); });
to see if I can get a handle on every path, and I can't. Is there something I am missing, or is there a way to assign onclick event handlers for each path?
Thank you rishi
Rishi source share