Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  153] [ 4]  / answers: 1 / hits: 47334  / 12 Years ago, sat, july 28, 2012, 12:00:00

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.


More From » jquery

 Answers
9

If you fill a <path> then clicking inside it (on the fill) will trigger the event handler:



Demo: http://jsfiddle.net/TmsrP/1/



<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:



Demo: http://jsfiddle.net/TmsrP/2/



<path fill=transparent … />

[#84008] Thursday, July 26, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaredsages

Total Points: 273
Total Questions: 97
Total Answers: 105

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
jaredsages questions
;