0

Lets say I have a RGB value of (0, 255, 0), how do I put that in a function which returns the hex value of it like below:

var rgbColor = div.backgroundColor; // Is stored as a rgb value
var hexVersion = rgbToHex(rgbColor);

function rgbToHex(rgb) {
    // Some code
    //return hex
}

The aim of this is to select a different element and set an input[type="color"]'s value to the background colour of an element but the only value you can set must be a hex so I need to convert the rgb to hex to do so, if anyone could help I would appreciate it greatly, thank you.

Bobby Mannino
  • 236
  • 2
  • 10
  • Welcome to [so], What have you tried? Make sure you've read the [How-to-Ask](https://stackoverflow.com/help/how-to-ask) tutorial, in order to ask your questions in a way that makes answering them rewarding. – umläute Dec 10 '20 at 21:32
  • What format does `rgbColor` take? Is it like `rgb(12, 34, 56)`? – Aplet123 Dec 10 '20 at 21:35

0 Answers0