JSFiddle - React, Tailwind, and code Playground
HTML
<div></div>
<ul id="ul">
</ul>
CSS
body{
background-color:white;
}
div{
color:red;
width:200px;
height:200px;
background:red;
}
ul{
height:100px;
width:200px;
margin:20px;
border:1px solid red;
background-color:red;
}
JavaScript
var color = '';
$(document).ready(function(){
var x = $('body').css('backgroundColor');
hexc(x);
alert(color);
document.getElementById("ul").style.backgroundColor = 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('');
}