kranthi kumar kranthi kumar - 3 months ago 15
jQuery Question

get content of <g> in SVG using javascript/jQuery

I have a bar graph developed in plotly and emded in a web app using iframe.
on mouse hover there is some content showing on the graph.
I dig down to see that the content is appending in

<g class="hoverover">
.
Is there any way I can get the content if the
<g>
is active using javascript/jQuery.

Answer

JavaScript

var i = document.getElementsByTagName("iframe")[0],
g = i.contentDocument.getElementByTagName("g")[0];

console.log(g.innerHTML);

jQuery

var i = $("iframe"),
$document = $(i[0].contentDocument);

console.log($document.find("g").html());