Reputation: 3364
I have a SVG map in my html with the <svg>
tag. and I want to attach events so I can click them and trigger some events. I know I can attach click event using jQuery on polygon elements. But some areas in this map are made using paths and I'd like to trigger some events when I click inside the paths, not on the paths.
What's the way to do that? Using jQuery is preferred.
Upvotes: 27
Views: 50309
Reputation: 303215
If you fill
a <path>
then clicking inside it (on the fill) will trigger the event handler:
<path id="sauce" fill="#f00" … />
$('#sauce').on('click',function(){ … });
You can choose to explicitly fill the path with the color transparent
and mouse events will still be caught:
<path fill="transparent" … />
Upvotes: 32