As I understand the getComputedStyles() method, it should return an object that allows one to access the actual CSS property values of an HTML element node.
I created this simple example with a paragraph containing 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 background color of the paragraph is orange
, so the span should also have that property value, or am I mistaken? Could it be that inherited values are ignored in getComputedStyles
? And if so, how can I get the actually visible background color for the span? Thank you.
` does.
– Zenoo Jan 09 '18 at 11:04