I'm trying to iterate through CSS styles. For example I get a style like this:
document.styleSheets[0].cssRules[10].style
That returns a CSSStyleRule
which is an object with both integer and string keys.
The integer and .length
keys can be used to iterate through the property assignments in the style, and each one gives the name of the property, for example:
document.styleSheets[0].cssRules[10].style[0] == "max-height"
The string keys give access to the actual actual text for the style like this:
document.styleSheets[0].cssRules[10].style["maxHeight"] == "100px"
So in theory it is easy to iterate through all the properties. But notice the maddening change from max-height
to maxHeight
! How can I deal with this? How do I even know what this mapping is? Do I just have to write a function that converts every -a
to A
and so on?