Add click event on elements of an embedded SVG in javascript

前端 未结 5 1820
鱼传尺愫
鱼传尺愫 2020-12-29 08:08

I got this SVG image from Wikipedia and embedded it into a website using this code:


5条回答
  •  囚心锁ツ
    2020-12-29 08:26

    If your SVG is contained in the DOM, you can attach event listeners to separate elements in the same manner as basic HTML. Using jQuery one example would be: http://jsfiddle.net/EzfwV/

    Update: Most modern browsers support inline svg, so to load your source into the DOM, all you have to do is load it in from a resource, (using something like jQuery's load()).

    Edit: more specific example http://jsfiddle.net/EzfwV/3/

提交回复
热议问题