How could one get an elements CSS property (for example width/height) as it was set with CSS rules, in whatever units it was set (eg percent/em/px)? (In Google Chrome, preferably frameworkless).
Using getComputedStyle
returns the current value in pixels, so does css()
in jQuery.
For example:
<div class="b">first</div>
<div id="a" class="a">second</div>
<style>
div { width: 100px; }
x, div#a { width: 50%; }
.a { width: 75%; }
</style>
While iterating all div
elements in this example, I'd like to be able to get the second div
s width as 50%
(and the first as 100px
).
Chrome element inspector can display CSS property value as they were set, so it should be possible in Chrome.
Not an exact duplicate of the linked question, as there the accepted answer there is a simple hack that produces a percentage width no matter what kind of width is set. And for the rest you have to know the selector used to make the active rule? How would one know that?