jquery - Find nearest polygon on svg -
https://codepen.io/jriggs/pen/yvpvwv
clicking on colored part of "childrens learning center" works expected, clicking on text returns letter path object, want polygon contains text
$("#svg_id > *").click(function () { ...do stuff $(this) }
the problem there shapes text 'on top' of polygon when click on them selected , not polygon. clicking on
i need getparerent svg. can edit svg code if necessary
i have tried use polygon selector, , jquerys closest:
$(this).closest('polygon')
and messing z-index properties no success. file given mefrom designer if there way export in more jquery friendly format may option. image floorplan many shapes , layers.
if want target clicked element in svg...
should use event target.
i don't know wish do...
console.log clicked ellemet class
, tagname
.
make more obvious visually, change fill
color cyan.
see in codepen.
$(document).ready(function () { $("#layer_1").click(function (e) { var eventtarget = $(e.target); var clickedclass = eventtarget.attr("class"); var clickedtagname = eventtarget[0].tagname; console.log("\na click occured on: " + clickedclass) console.log("which a: " +clickedtagname); // action if target not paths (assuming letters) , not text if( clickedtagname != "path" && clickedtagname != "text" ){ eventtarget.css({"fill":"cyan"}); } }); });
Comments
Post a Comment