SVG get text element width

var bbox = textElement.getBBox();
var width = bbox.width;
var height = bbox.height;

and then set the rect’s attributes accordingly.

Link: getBBox() in the SVG v1.1 standard.

Leave a Comment