I have an svg embedded in HTML using an object tag
<div id="svgDiv">
<object id="svgObjectElement" data="mysvg.svg" type="image/svg+xml">
Your browser doesn't support SVG.
</object>
</div>
I want to use the tippy.js library to provide tooltips for circles in my svg, but I can't seem to get tippy to use the circles in mysvg as targets. If the svg is in the HTML (like this line element) it works great.
HTML:
<svg height="50" width="50"><line x1="0" y1="0" x2="50" y2="50" style="stroke:tomato;stroke-width:5"></line></svg>
<div id="svgDiv">
<object id="svgObjectElement" data="mysvg.svg" type="image/svg+xml">
Your browser doesn't support SVG.
</object>
</div>
JavaScript:
tippy('line', {
content: 'Custom Line Tooltip',
})
I have tried the following JavaScript where circle1 is the id of a circle in the svg but it doesn't work:
var svgDocument = document.getElementById("svgObjectElement").contentDocument;
var element = svgDocument.getElementById("circle1");
tippy(element, {
content: 'Custom circle Tooltip',
});
I have also tried
var svgDocumentElement= document.getElementById("svgObjectElement").contentDocument.documentElement;
var element = svgDocumentElement.getElementById("circle1");
tippy(element, {
content: 'Custom circle Tooltip',
});
which doesn't work. I am using Chrome if that is relevant. Any ideas would be appreciated.