In the DOM, one can traverse down into an embedded SVG element using getSVGDocument()
. For instance, with an HTML document like this:
<div id="container">
<embed id="svg-wrap" src="pic.svg"></embed>
</div>
I can access the structure of the SVG itself by doing this:
var svg_wrap = document.getElementById("svg-wrap");
var svg = svg_wrap.getSVGDocument();
How do I reverse this and go from the SVG element up to the enclosing embed and div elements? At least in Chrome 43.0.2357.81, normal DOM traversal methods don't work at the SVG/HTML boundary. For context, I want this so that I can calculate an SVG element's location on the page.