Adamarla
Adamarla

Reputation: 812

SVG - Get font-size of a TextElement

How do I get the font size of a SvgTextElement when it could be set by CSS and/or inherited?

'getAttributeNS' only works if the Element has the property directly applied. I think it may require 'baseVal' but I'm having no luck.

Browsers: IE + Adobe Svg Viewer Firefox Chrome IE9

Upvotes: 1

Views: 2871

Answers (2)

Argent
Argent

Reputation: 945

This is really more in the nature of a comment. The following slightly simpler formulation works:

var fontSize = window.getComputedStyle(element).fontSize;

If you want to be able to search on the phrase 'font-size' then the following works:

var fontSize = window.getComputedStyle(element)['font-size'];

Upvotes: 1

Robert Longson
Robert Longson

Reputation: 124059

var fontSize = window.getComputedStyle(element, null).getPropertyValue("font-size");

where element would be the result of document.getElementById or something similar.

Upvotes: 5

Related Questions