如何访问 <img> 中 SVG 文件的内容?元素? [英] How do you access the contents of an SVG file in an &lt;img&gt; element?

查看:27
本文介绍了如何访问 <img> 中 SVG 文件的内容?元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设你的 HTML 中有这个:

Say you have this in your HTML:

您将如何通过 JavaScript 访问 example.svg 的内容(即 等)?

How would you access the contents ( ie. <rect>, <circle>, <ellipse>, etc.. ) of the example.svg via JavaScript?

推荐答案

无法从 img 元素获取引用的 svg 的 DOM.

It's not possible to get the DOM of a referenced svg from the img element.

如果您使用