Please consider 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 gives back the exact input for backgroundColor
in IE 11 and Firefox 37, but in Chrome 43 it changes the alpha-value, and the alert says:
rgba(124, 181, 236, 0.247059)
Notice that the alpha-value unexpectedly returns 0.247059
instead of 0.25
.
I've gone through the background-color
spec as well as the rgba spec and more specifically the bit about alpha values, but failed to determine whether this is a bug or if the UA (in this case Chrome) is allowed to do this.
Does any of the relevant specs explain whether Chrome's behavior is "allowed"? As a bonus, can anyone explain why Chrome would subtly change the alpha-value?
Footnote: to check if it is the "setter" (el.style.backgroundColor = ...
) is to blame I've also tried declaring the style on 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>