How do I write a RGB color value in JavaScript?

前端 未结 6 1569
不知归路
不知归路 2020-12-28 13:09

I am trying to change the color of the function swapFE() below and I can\'t figure out how to write it. I was told to change the color of the phrase node to the color value

6条回答
  •  清歌不尽
    2020-12-28 13:35

    I am showing with an example of adding random color. You can write this way

    var r = Math.floor(Math.random() * 255);
    var g = Math.floor(Math.random() * 255);
    var b = Math.floor(Math.random() * 255);
    var col = "rgb(" + r + "," + g + "," + b + ")";
    parent.childNodes[1].style.color = col;
    

    The property is expected as a string

提交回复
热议问题