JSFiddle - React, Tailwind, and code Playground
CSS
div{
width:auto;
height:10px;
background-color:red
}
JavaScript
var myclickhandler = function(x) {
alert("clicked");
console.log(x);
}
for (i= 0;i <10 ; i++)
{
var div = document.createElement('div');
div.innerHTML = i + "Node";
var x = div.innerHTML;
document.body.appendChild(div);
//div.onclick = myclickhandler(x);
// closure
div.onclick = function(x)
{
return function()
{
myclickhandler(x);
}
}(x);
}