How can I compute the used style values of an element (instead of the computed style values)?
In this code, I am using getComputedStyle
, and the output says that subdiv has computed display = block
, eventhough it is not displyed.
How can I modify the code to get a used display = none
, as everybody would expect?
<html><body>
test
<div id="maindiv" style="display: none">
maindiv
<div id="subdiv" style="display: block">subdiv</div>
</div>
<script>
alert(window.getComputedStyle(document.getElementById("subdiv")).display)
</script>
</body></html>
From https://developer.mozilla.org/en-US/docs/Web/CSS/used_value
"used value" vs "computed value"
CSS 2.0 defined only computed value as the last step in a property's calculation. Then, CSS 2.1 introduced the distinct definition of used value. An element could then explicitly inherit a width/height of a parent, whose computed value is a percentage. For CSS properties that don't depend on layout (e.g., display, font-size, or line-height), the computed values and used values are the same. The following are the CSS 2.1 properties that do depend on layout, so they have a different computed value and used value: (taken from CSS 2.1 Changes: Specified, computed, and actual values):