How can I read out the CSS text via Javascript as defined in the stylesheet?

Posted by Monokai on Stack Overflow See other posts from Stack Overflow or by Monokai
Published on 2010-06-13T06:55:18Z Indexed on 2010/06/13 7:02 UTC
Read the original article Hit count: 171

Filed under:
|
|

I was thinking of using Javascript to automatically transform CSS3 attributes like border-radius, transform, box-shadow, etc. to their browser specific counterparts.

I did some research and found that you can iterate over the stylesheets defined via document.styleSheets. You can find the CSS rules via document.styleSheets[0].cssRules[0].cssText.

I want to modify the CSS rules that contain CSS3 attributes by injecting the browser specific attributes with the appropriate vendor-prefix, like -webkit-border-radius, moz-border-radius, etc.

However, it seems that the cssText property is preprocessed in each browser, to filter out CSS attributes that it doesn't understand. That practically breaks this idea.

Question: is there any way to retrieve the CSS text exactly as defined in the stylesheet? Or: is there another way to accomplish this via Javascript? I'd like to maintain clean CSS files without the need for defining each attribute multiple times for each specific browser.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about css