Answers for "how to convert rgb color value to color name javascript"

0

javascript convert hex color to rgb

function rgbToHex(r, g, b) {
  return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}

function hexToRgb(hex, result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)) {
  return result ? result.map(i => parseInt(i, 16)).slice(1) : null
  //returns [23, 14, 45] -> reformat if needed
}

console.log(rgbToHex(10, 54, 120)); // #0a3678
console.log(hexToRgb("#0a3678")); // [10, 54, 120]
Posted by: Guest on April-06-2022
0

javascript set color in hex

element = document.querySelector("div");
element.style.backgroundColor = "#242424";
Posted by: Guest on October-09-2020

Code answers related to "how to convert rgb color value to color name javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language