SixDegrees
SixDegrees

Reputation: 793

Get Height of SVG String

I'm trying to get the height of an SVG string. I'm getting the width with getComputedTextLength(), which works well, but there doesn't seem to be any equivalent for height.

getBBox() is not an option. It is no longer supported in Firefox, at least not for text, apparently because it is part of SVG 2.0.

Upvotes: 0

Views: 1082

Answers (2)

philipp
philipp

Reputation: 16515

For any Element you can use getBoundingClientRect(). have a look here for documentation. In some Browsers the returned rect does not have a height property, but by simple subtracting rect.bottom - rect.top you got it.

Please not that getBoundingClientRect() will return values in absolute space, whereby getBBox() returns values in user space of the element, what can be confusing if it has applied transformations.

Upvotes: 2

Paul LeBeau
Paul LeBeau

Reputation: 101820

getBBox() should work fine for text elements on Firefox.

Here's a demo to prove it.

This worked fine for me in FF 32.

Upvotes: 2

Related Questions