Why not working code (JavaScript)?

Why when the color of the point in HEX (#ffffff) doesn't work, and word work (red, green)
6, 7, 9, 15 row
not working
March 16th 20 at 14:30
1 answer
March 16th 20 at 14:32
element.style.backgroundColor returns the result in the form 'rgb(red,green,blue)'
Need to translate first in hex
function rgb2hex(rgb) {
 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
 function hex(x) {
 return ("0" + parseInt(x).toString(16)).slice(-2);
 return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);

color = color.indexOf("rgb") !== -1 ? rgb2hex(color) : color;

And the color options be set in lowercase "#0acf00"
And why had had no such problems? - jovan95 commented on March 16th 20 at 14:35
It depends from the browser, try different browsers. - emory.Fisher81 commented on March 16th 20 at 14:38
The style is better to take
let style = getComputedStyle(document.getElementById('radio'));
In your example(to change properties) backgroundColor === ". After the first time change - returns the actual color. I.e. is the scope of JS: element.style visible only those properties that have changed by JS. But on the performance in your example is not affected. - emory.Fisher81 commented on March 16th 20 at 14:41

Find more questions by tags Work with colorHexJavaScriptCSS