JSFiddle - React, Tailwind, and code Playground
HTML
<div id="container"></div>
JavaScript
class ButtonToPress {
constructor(n) {
this.n = n;
const button = document.createElement('button');
button.onclick = this.print;
button.innerText = this.n
button._cc = this;
document.getElementById('container').appendChild(button);
window.b1 = button;
}
print() {
this._cc.n++;
console.log(this._cc);
this.innerText = this._cc.n;
}
}
let buttons = [];
for (let i = 0; i < 1; i++) {
buttons[i] = new ButtonToPress(i);
}