How do you access the contents of an SVG file in an element?

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

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.

Here’s an example showing how to get the DOM of a referenced svg.

Leave a Comment