My understanding of the getComputedStyles() method is that it returns an object enabling access to the actual CSS property values of an HTML element node.
I decided to test this concept by creating a simple example with a paragraph that contains a span:
let span = document.getElementsByTagName("span")[0];
let style = window.getComputedStyle(span);
span.innerText = "span background-color is " + style.getPropertyValue("background-color");
<p style="background-color: orange">
<span style="color: green">Empty</span>
</p>
The paragraph's background color is orange
, so should the span inherit that property value, or am I mistaken? Could it be possible that inherited colors are not considered in getComputedStyles
? If so, how can I retrieve the true visible background color for the span? Thank you.