Pay attention to the following snippet:
var el = document.getElementById('x'); el.style.backgroundColor = "rgba(124, 181, 236, 0.25)"; alert(el.style.backgroundColor);
<div id="x">Testing</div>
On Windows 8.1, this returns the exact input for backgroundColor in IE 11 and Firefox 37, but in Chrome 43 it changes the alpha value, and the warning says:
rgba (124, 181, 236, 0.247059)
Note that the alpha value unexpectedly returns 0.247059 instead of 0.25 .
I went through the background-color specification , as well as the rgba specification and more specifically the bit about alpha values , but could not determine if this is an error, or if UA (in this case Chrome) is allowed to do this.
Does any of the relevant specifications comply with Chrome behavior? As a bonus, can anyone explain why Chrome subtly changes the alpha value?
Footnote: checking if this is a "setter" ( el.style.backgroundColor = ... ) is to blame. I also tried to declare the style of the element inside the DOM itself. This will have the same (unexpected) result. See this snippet:
document.addEventListener("DOMContentLoaded", function(event) { var el = document.getElementById('x'); alert(el.style.backgroundColor); });
<div id="x" style="background-color: rgba(124, 181, 236, 0.25);">Testing</div>
source share