Last Updated: February 25, 2016
·
416
· 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