How do I parse @import stylesheets with Javascript

后端 未结 3 1588
臣服心动
臣服心动 2021-02-06 01:19

I am trying to read CSS selectors in my stylesheets with the document.styleSheets array. It works fine with and

... then document.styleSheets.length is 2 (the link tag and the style tag). The CSS file that is linked through @import will be available as

document.styleSheets[1].cssRules[0]. 

In other words, a CSS rule. This can also be seen at the Quirksmode page that you mentioned, Christoph. I can get its cssText ("@import url('css/test2.css');") but I can't figure out how to parse the CSS inside the file (test2.css)...

If I have totally missed something obvious here, feel free to ridicule me... :)

提交回复
热议问题