JSFiddle - React, Tailwind, and code Playground

HTML

<div class="clickme" style="background:#000000; width:50px; height:50px; float: left; margin:4px"></div>
<div  class="clickme" style="background:#c9c9c9; width:50px; height:50px; float: left; margin:4px"></div>

<div id="result"></div>

JavaScript

$('.clickme').click(function(){
      $('#result').html( rgb2hex($(this).css('background-color')));
   });

function rgb2hex(rgb) {
    rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    function hex(x) {
        return ("0" + parseInt(x).toString(16)).slice(-2);
    }
    return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}