JSFiddle - React, Tailwind, and code Playground
by jstenkvist
HTML
<div></div>
CSS
div{
color:red;
width:200px;
height:200px;
background:rgb(254,254,0);
}
JavaScript
$('div').click(function() {
var x = $(this).css('backgroundColor');
alert(hexc(x));
})
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('');
return color
}