Say you have this in your HTML:
<img src='example.svg' />
How would you access the contents ( ie. <rect>, <circle>, <ellipse>, etc.. ) of the example.svg via JavaScript?
<rect>, <circle>, <ellipse>
It's not possible to get the DOM of a referenced svg from the img element.
img
If you use <object>, <embed> or <iframe> however then you can use .contentDocument (preferred) to get the referenced svg, or .getSVGDocument which may be more compatible with old svg plugins.
<object>
<embed>
<iframe>
.contentDocument
.getSVGDocument
Here's an example showing how to get the DOM of a referenced svg.
1.4m articles
1.4m replys
5 comments
57.0k users