Listing known CSS classes using Javascript

前端 未结 5 2033
傲寒
傲寒 2020-12-19 00:56

I\'m trying to find a good way to collect the names of classes defined in the stylesheets included with a given document. I know about document.StyleSheetList b

5条回答
  •  情话喂你
    2020-12-19 01:09

    You were on track with document.styleSheets (https://developer.mozilla.org/en/DOM/document.styleSheets)

    https://developer.mozilla.org/en/DOM/stylesheet.cssRules

    Here's a quick and dirty method to output all class selectorTexts to the console in Firefox + Firebug.

        var currentSheet = null;
        var i = 0;
        var j = 0;
        var ruleKey = null;
    
        //loop through styleSheet(s)
        for(i = 0; i

提交回复
热议问题