39

I have come across an interesting bug (?) whereby if you embed the SVG using <use> as part of a link (an icon for example) – the icon itself does not register a click event in jQuery, but clicking the text does. I think this is due to SVG events not bubbling up?

If you embed the SVG directly, the link triggers regardless of whether you click the text or the icon.

A simple test case I created can be seen here: SVG <use> bug test case.

Erik Dahlström
  • 59,452
  • 12
  • 120
  • 139
Paul Thomas
  • 2,756
  • 2
  • 16
  • 28

3 Answers3

66

Use pointer-events: none; on the svg. It worked for me.

The element is never the target of mouse events; however, mouse events may target its descendant elements if those descendants have pointer-events set to some other value. In these circumstances, mouse events will trigger event listeners on this parent element as appropriate on their way to/from the descendant during the event capture/bubble phases.

https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events

Aziz Abogoda
  • 776
  • 7
  • 5
5

I had the same problem. The fix I use is to just put a transparent div over the svg. But that is not ideal of course.

Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160
0

I had the same problem and I used display: block or display: inline-block on the link and it worked.

vich
  • 11,836
  • 13
  • 49
  • 66