Get CSS properties values for a not yet applied class

后端 未结 2 832
再見小時候
再見小時候 2021-01-18 03:18

In jQuery, I can get a CSS property value for a selector using the css method and passing a property name, for example:

$(\'#myElement\').css(\'backgr

2条回答
  •  Happy的楠姐
    2021-01-18 03:26

    Short answer: You cannot get a css property from a class that is not applied to any element. However, you can directly read it from a CSS stylesheet and you can do this by using DOM CSS

    And then maybe have something like:

    var bgimage = myStyleSheet.cssRules[0].style.background-image;
    

提交回复
热议问题