Luke Snowden
Luke Snowden

Reputation: 4196

Snapsvg - get height and width of text element

I am altering the elements contents using

svgTextLines[name].node.innerHTML = line.val();
svgTextLines[name].node.textContent = line.val();

and trying to get the height and width of the element after the content has changed but I cant seem to find any property in the elemement.node object that gets updated. As the element has not transformed I can understand why but is there a way I can get this information?

Regards

Upvotes: 0

Views: 2117

Answers (1)

canonale
canonale

Reputation: 37

I'm using SnapSVG and I had the same problem. You can use getBoundingClientRect to get an object with this parameter.

var s = Snap("#svg");
Snap.load("mascot.svg", function (f) {
  s.append(f);
  var rect = s.searchAll("g")[0];
  var dimens = rect.node.getBoundingClientRect();     
  console.log(dimens.width)
});

Upvotes: 1

Related Questions