Last Updated: February 25, 2016
·
670
· narkir

Handle mouse click on links with SVG graphics

Other day I faced this problem. If you place SVG into a tag, that is observed with javascript, and then click on zone with graphics, listeners are ignored.

So I've found this solution:

$ ->
  # Select only links with event bindings. In Rails they have data-method attribute.
  $('a[data-method] svg').click (e) ->
    e.preventDefault()
    e.stopPropagation()
    $(this).parent().click()

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside