I try something like this:
if(elem.css.fill==='rgb(255,255,255)')
but it doesn't work.
I try something like this:
if(elem.css.fill==='rgb(255,255,255)')
but it doesn't work.
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, wherergb(255,255,255)
andrgb(255, 255, 255)
is considered as different when you compare it as a string value