artsiomshushkevich
artsiomshushkevich

Reputation: 23

getBBox function returns object with zero-valued properties from dynamically created text SVG node

I'd like to get width of dynamically created text SVG node. Here's my code snippet.

var textSvgElement = document.createElementNS('http://www.w3.org/2000/svg','text');
textSvgElement.setAttribute('style', '12px');
textSvgElement.setAttribute('x', '10');
textSvgElement.setAttribute('y', '20');
textSvgElement.appendChild(document.createTextNode('some text'));
var textSvgElementDataObj = textSvgElement.getBBox();

But textSvgElementDataObj variable always contains object with zero-valued properties like on image:

enter image description here

Could anyone give me some pieces of advice how to resolve this problem?

Upvotes: 1

Views: 639

Answers (1)

Robert Longson
Robert Longson

Reputation: 124089

attach the textSvgElement to the document first.

Upvotes: 1

Related Questions