JSFiddle - React, Tailwind, and code Playground
by Tri Nguyen
HTML
<div id="container"></div>
JavaScript
var i = 0; //I set this to be constant, you can use it in a loop
var btn = document.createElement("BUTTON");
var text = document.createTextNode("Click me");
var expNo = "exp" + i; //set the id as a variable -> use it for later
btn.setAttribute("id", expNo);
btn.appendChild(text); //add text to button
document.getElementById("container").appendChild(btn); //add button to container
var button = document.getElementById(expNo);
button.onclick = alertMe;
function alertMe() {
alert("I have been clicked");
}