开发者

Get unrecognized styles from stylesheet in JS

How can I get the actual te开发者_JS百科xt of a stylesheet using JS?

The cssRules property only returns those rules that it recognizes.

eg. I would like to change -webkit-border-radius to -moz-border-radius. Or do some JS wizardry to any element who's style contains myTrigger:true; (Do NOT lecture me on principal.)

Cycling through document.stylesheet's cssRules returns the parsed text minus any unrecognized rules, whether I use cssText, the array of rules, or the default rules.

Is there any way to parse an included stylesheet and view/modify each of the rules as it was actually written?


The only way to do this is to load the stylesheet directly with a JavaScript xmlhttprequest then parse the contents yourself. Then, after doing that, use the JavaScript to insert your modified styles into the head of the HTML document.

Messy, but it'll work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜