Find all CSS rules that apply to an element

后端 未结 9 825
温柔的废话
温柔的废话 2020-11-22 10:26

Many tools/APIs provide ways of selecting elements of specific classes or IDs. There\'s also possible to inspect the raw stylesheets loaded by the browser.

However,

9条回答
  •  不思量自难忘°
    2020-11-22 11:10

    EDIT: This answer is now deprecated and no longer works in Chrome 64+. Leaving for historical context. In fact that bug report links back to this question for alternative solutions to using this.


    Seems I managed to answer my own question after another hour of research.

    It's as simple as this:

    window.getMatchedCSSRules(document.getElementById("description"))
    

    (Works in WebKit/Chrome, possibly others too)

提交回复
热议问题