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

How can I prevent click handler action on the whitespace around an SVG path?

I have this image here which is SVG format, when the user clicks this image some action happens.

One problem there, this image has some white empty space around it that can’t be removed because it’s not a quadrilateral.

What I need is when the user clicks this empty space around the image don’t do the action, I want the action to happen only if the user clicks this pink colored part in the image.

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

I can use either JavaScript or jQuery.

enter image description here

>Solution :

you could export this image as an SVG File and attach the click event to the svg path.

document.querySelector('svg path').addEventListener('click', () => console.log('clicked');

Working demo : https://codepen.io/brieuc-dot/pen/LYrpwEz

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