JSFiddle - React, Tailwind, and code Playground
by naokiota
HTML
<a style="background-color: #ff0000;" onclick="changeColor(this)" href="#">Click me</a>
<script>
function changeColor(obj) {
var color = rgb_to_hex(obj.style.backgroundColor);
if (color=="#ff0000") {
obj.style.backgroundColor="#00ff00";
} else if (color=="#00ff00") {
obj.style.backgroundColor="#0000ff";
} else {
obj.style.backgroundColor="#ff0000";
}
}
function rgb_to_hex(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]);
}
</script>