JSFiddle - React, Tailwind, and code Playground
by mattdlockyer
HTML
<div id="0"></div>
<div id="1"></div>
<div id="2"></div>
CSS
div {
width:100px;
height:100px;
background:red;
margin:10px;
}
JavaScript
var products = ['a', 'b', 'c'];
for (var i = 0; i < 3; i++) {
(function() {
var product = products[i];
$('#' + i).on('click', function () {
alert(product);
});
})();
}