Add click event on elements of an embedded SVG in javascript

前端 未结 5 1822
鱼传尺愫
鱼传尺愫 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:31

    Here's an example that should be very similar to what you're trying to do. It uses instead of , but that's only a minor detail. See this other example for how to get to the DOM of the embedded document from the parent document, it differs just a bit between the two.

    Also note that the svg maps that wikipedia have are quite large, so you will want to optimize the svgs before actual usage on a live website, try e.g SVG Cleaner or SVG Scour.

    提交回复
    热议问题