How to get SVG of clicked element in page with multiple svgs.
I prefer not to go up the parentNode chain till I find it is an SVG node. Thanks.
How to get SVG of clicked element in page with multiple svgs.
I prefer not to go up the parentNode chain till I find it is an SVG node. Thanks.
The SVGElement interface exposes an ownerSVGElement property that will expose just that information:
document.querySelector('rect').onclick = function(evt) {
console.log(this.ownerSVGElement.id);
};
click the rect<br>
<svg id="find_me">
<rect width='200' height='200'/>
</svg>