Search code examples
javascriptcsshsl

How to set hsl color on CSSStyleDeclaration object?


How to set hsl color on CSSStyleDeclaration object?

//CSS
background-color: hsl(155,100%,30%);

//JavaScript
divElement.style.backgroundColor = ?;

I don't want to use HEX value or color name in javascript.

Please suggest.

W3C standard link would be a great help too.

i hesitate to set hsl string as I didn't find it in W3C CSSOM or DOM standard.


Solution

  • Just set it as a string

    divElement.style.backgroundColor = "hsl(155,100%,30%)";
    

    Demo: http://jsfiddle.net/maniator/gg7JN/