JSFiddle - React, Tailwind, and code Playground

HTML

<div id="myTest"></div>

JavaScript

for (var i = 0; i < 5; i++) {
    var divTest = $('<div></div>')
    divTest.text("My Div " + i);
    (function(i) {
        divTest.click(function() {
            alert("Div: " + i);
        });
    })(i);
    $('#myTest').append(divTest);
}