JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" class="green">Green</a>
<a href="#" class="red">Red</a>
<a href="#" class="blue">Blue</a>
JavaScript
var colors = ['green', 'red', 'blue'],
clickEvent = function(position) {
return function() {
alert("My favorite color is " + colors[position]);
};
};
for(var i=0; i<colors.length; i++) {
document.getElementsByClassName(colors[i])[0].onclick = clickEvent(i);
}