How to get cascaded style value or determine whether the actual value was computed?

Viewed 745

I need to get a cascaded style value of an element (not the computed one), or to determine whether the actual value was computed or not.

For example, if I have an element with css rule width: 100%, I want to get the value 100% and not the actual pixels value, or just to know that the actual value was computed.

I know that I can get it using elem.currentStyle, and I also found a way in Chrome to find it using document.defaultView.getMatchedCSSRules().

Does anyone know a way to get it in other browsers?

4 Answers

What about calculating the value yourself? Query the calculated width of the wanted element and the calculated width af the parent element and then do some math to get the percentage-value? percentageValue = 100% * widthOfWanted / widthOfContainer

At this point I don't think there is a built-in way to do that in browsers other than IE: getComputedStyle will always just return the used value for those properties, like you said.

Related