JSFiddle - React, Tailwind, and code Playground

by J. Albert Bowden

HTML

<div></div>

CSS

div{
    color:red;
    width:200px;
    height:200px;
    background:red;   
}

JavaScript

var color = '';
$('div').click(function() {
    var x = $(this).css('backgroundColor');
    hexc(x);
    alert(color);
})

function hexc(colorval) {
    var parts = colorval.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    delete(parts[0]);
    for (var i = 1; i <= 3; ++i) {
        parts[i] = parseInt(parts[i]).toString(16);
        if (parts[i].length == 1) parts[i] = '0' + parts[i];
    }
    color = '#' + parts.join('');
}