1

I try something like this:

if(elem.css.fill==='rgb(255,255,255)')

but it doesn't work.

Konamiman
  • 49,681
  • 17
  • 108
  • 138
Grosy
  • 29
  • 4

1 Answers1

2

You can use getComputedStyle() to get the list of possible css properties and then look for the value of fill style to match with the expected rgb() value.

let elem = document.querySelector('span');
let style = getComputedStyle(elem);
if (style.fill === 'rgb(255, 255, 255)') {
  console.log('matched!');
}
.circle {
  fill: rgb(255,255,255);
}
<span class="circle">Circle</span>

Note that there is a spacing issue while you compare the rgb() values, where rgb(255,255,255) and rgb(255, 255, 255) is considered as different when you compare it as a string value

Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62