SVG - Get font-size of a TextElement

后端 未结 2 1994
囚心锁ツ
囚心锁ツ 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'];
    
    0 讨论(0)
  • 2020-12-20 05:26

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

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

    0 讨论(0)
提交回复
热议问题