JSFiddle - React, Tailwind, and code Playground

JavaScript

colVal = ["#ffffff", "#cccccc", "#ff6600"];
for(var i = 0; i < colVal.length; i++) {
    $("body").append('<button class="colors" style="background-color: ' + colVal[i] + ';">click!</button>');
}

$(".colors").click(function(e) {
    var thisColorRgb = $(e.target).css("background-color");
    
    var thisColorHex = $(this).attr("style").substring($(this).attr("style").indexOf("background-color:") + 17, $(this).attr("style").indexOf(";", $(this).attr("style").indexOf("background-color:"))).trim();
    
    alert("this color as HEX:   " + thisColorHex + "\n and as RGB:   " + thisColorRgb);
});