I am working with d3js where lib create nodes and links according to data. At some place have some specific requirement to add multiple text in same line like url "www.xyz.com/home/user" (here 3 strings "www.xyz.com","/home","/user"). They are not separate nodes so I can't find position with d3. It's just a <text> element with 3 <tspan> children.
<text id="TaxFilingResource_URL" class="label url" dy="24" dx="30">
<tspan id="TaxFilingResource.URL.1">www.xyz.com</tspan>
<tspan id="TaxFilingResource.URL.2">/home</tspan>
<tspan id="TaxFilingResource.URL.3">/user</tspan>
</text>
and displaying like this below
www.xyz.com/home/user
I need to get the position and width of each <tspan> element. My code is
var el = document.getElementById(d.source);
x = el.getStartPositionOfChar('').x (or)
x = el.getClientRects().left;
that give relative position on text inside g element , but in some browser and on mac it will return absolute position.
Is there any right way to find position and width of tspan in JavaScript that worked with all browsers ( IE must > 9th version).