After taking a look at this particular post on Stack Overflow about
How to retrieve the background color of an element using javascript?I discovered that by using
div.style.color
You can access the color applied to the div element.
However, it seems that this method only works if the style is set inline on the element.
So, the question is: how can you retrieve the style of an element when it is applied through a style sheet or within tags, rather than directly inline?
Take a look at the example provided below:
console.log(document.getElementById('content').style.backgroundColor);
console.log(document.getElementById('content').style.color);
#content {
background-color: #000000;
display: inline-block;
height: 100px;
width: 100px;
}
<div id="content" style="color:red;"></div>
console.log(document.getElementById('content').style.backgroundColor);
yields no result
console.log(document.getElementById('content').style.color);
returns red