The CSS value is returned in a particular way.
Try comparing it to: "rgba(213, 212, 212, 0.5)"
(spaces after each comma).
Since JavaScript's rounding errors are the worst, and you really don't care about the alpha, you can just cut out the part you need:
var color = document.getElementById('element').style.backgroundColor;
color = color.substring(
color.indexOf('(') + 1,
color.lastIndexOf(color[3] == 'a' ? ',' : ')')
);
if (color == '213, 212, 212')
{
alert("MATCHED");
}
else
{
alert("FAILED");
}
Works whether or not it's rgb
or rgba
If the background-color
is not defined as an inline-style, you might want to use:
var color = window.getComputedStyle(document.getElementById('element')).backgroundColor;
instead (of the first line in code).