[Racine des codes] [Page précédente]

rgb2hex

/Html JavaSript/rgb2hex.html
<script type="text/javascript">
function hexColor(styleColor) {
  var dec, hex = styleColor;
  if (dec = hex.match(/^rgb\(([0-9]+), *([0-9]+), *([0-9]+)\)$/)) {
    hex = (1*dec[3] + 256*dec[2] + 65536*dec[1]).toString(16);
    while(hex.length<6) hex = "0"+hex;
    hex = "#"+hex
  }
  return hex;
}
</script>

<div id="teste" style="color: #0033FF;">POUETTE</div>
<input type="button" onclick="alert(hexColor(document.getElementById('teste').style.color))" value="hexColor(style.color)">
[edit]