JSFiddle - React, Tailwind, and code Playground
HTML
<div class="jump-response">one</div>
<div class="jump-response">two</div>
<div class="jump-response">three</div>
<div class="jump-response">four</div>
<div class="jump-response">five</div>
JavaScript
function get_random_color() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.round(Math.random() * 15)];
}
return color;
}
function rgb2hex(rgb) {
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
$(function() {
$(".jump-response").each(function() {
$(this).css("background-color", get_random_color());
});
$(".jump-response").mouseover(function() {
console.log(rgb2hex($(this).css('background-color')));
});
});