JSFiddle - React, Tailwind, and code Playground
HTML
<div class="color_me"></div>
CSS
.color_me {
display: block;
height: 50px;
cursor: pointer; /* No, we don't care about IE5.5 which won't understand this (it expects "hand" instead) */
width: 50px;
}
JavaScript
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.round(Math.random() * 15)];
}
return color;
}
$('.color_me').css("background-color", getRandomColor);
$('.color_me').click(function() {
$(this).css("background-color", getRandomColor);
});