Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SVG: Get clicked element

How to get the specific element inside SVG on which click was made?

    this.svgEl = document.createElementNS('http://www.w3.org/2000/svg', 'svg');        
    var s = Snap(this.svgEl);        
    var svgFromApi = (new DOMParser()).parseFromString("svg image from API", "image/svg+xml");
    s.clear();
    s.append(svgFromApi.documentElement);
    this.divElementRef.nativeElement.appendChild(this.svgEl); 

    this.svgElement.onclick = ()=> {               
           //Need to get on which element inside SVG it was clicked.   
       }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this

this.svgEl.onclick = (event) => {               
   // event.target should contain the element that was clicked on
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading