JSFiddle - React, Tailwind, and code Playground

HTML

<div id="container">

</div>

JavaScript

for (var i = 1; i<10; i++) {

	var newButton = document.createElement("button");
  newButton.innerHTML = "Button" + i;
  newButton["data-i"] = i;
  
  // each button should alert the number cooresponding to the iteration in which it was created
	newButton.onclick = function() {
  	alert(this["data-i"])
   	};
  
	document.getElementById('container').appendChild(newButton);

}