Listing known CSS classes using Javascript

前端 未结 5 2026
傲寒
傲寒 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:17

    What about

    .something .other_something?

    Do you want a pool of classNames that exist? Or a pool of selectors?

    Anyway, have you tried iterating through document.styleSheets[i].cssRules? It gives you the selector text. Parsing that with some regexp kungfu should be easier...

    Do you need it to be crossbrowser?

提交回复
热议问题