I'm trying to use the getBBox method to get the width of a text element inside an SVG render, BUT for some odd reason it only works half the time, the other half it fails..
Here's my JS code I'm using for that:
console.log(iElement.find('.yLabel2:eq(2)')[0].getBBox());
var passWidth = numberTitle2.node().getBBox().width;
So half the time it will log [object SVGRect]
and set passWidth to the width, that's awesome. BUT the other times it logs [object Exception]
, doesn't log the width, and breaks the rest of the JavaScript following it.
Inside the Exception object there's name: "NS_ERROR_FAILURE"
and result: 2147500037
Any ideas on how to get this to work smoothly or a better way to get the width of an svg element?
It fails in Firefox if the text is not rendered. E.g. it is display:none or you've not attached it to the document.