'How can i make JavaScript If Style Color work?

I have a simple if condition that checks the color of a element...

function changeBackgroundColor(element) {
          if (element.target.style.color == "#1abc9c"){
            // Do nothing
          } 
          else { // Whatever }

But it is not working. If i use common names like "Yellow, green, etc" it works. Any tips?



Solution 1:[1]

document.getElementById('main').style.color returns a RGB value, not a HEX value.

Example:

if (document.getElementById('main').style.color == 'rgb(26, 188, 156)') {
    console.log("Colour is set")
} else {
    
}
<div id="main"  style="color: #1abc9c">
    Hello, world!
</div>

<script src="test.js"></script>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Daniel