Skip to content Skip to sidebar Skip to footer

Javascript Style Object Converts Complex Color Names Into Rgb

Is there a way to override how javascript converts complex CSS color names to rgb values when applying them to DOM elements in the document.getElementById(xxx).style object. For ex

Solution 1:

You could use setAttribute:

element.setAttribute('style', 'background-color: lightblue');

To preserve the existing inline style:

var box = document.getElementById("box"),
    old_style = box.getAttribute('style');

box.setAttribute('style', old_style + ' background-color: lightblue;');

DEMO

Notice that the inline background-color is 'lightblue' and not 'rgb(173, 216, 230).'


Post a Comment for "Javascript Style Object Converts Complex Color Names Into Rgb"