SVG - Get font-size of a TextElement

后端 未结 2 1993
囚心锁ツ
囚心锁ツ 2020-12-20 04:45

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 a

2条回答
  •  执念已碎
    2020-12-20 05:22

    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'];
    

提交回复
热议问题