Как повесить событие onclick, на метод AlertOn(), на динамически создаваемый button?
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div class="headall" id="allhead">Меню</div>
<div class="bodyall" id="allbody"></div>
</body>
</html>
class Menu {//Menu
constructor(name, hod) {//construct
this.name = name;
this.hod = hod;
this.AlertOn = function (){
alert(this.hod);
}
countMenu++;
}//endconstruct
}//endMenu
countMenu = 0;
menu1 = new Menu("Меню 1", "1");
menu2 = new Menu("Меню 2", "2");
menu3 = new Menu("Меню 3", "3");
menu4 = new Menu("Меню 4", "4");
for(j = 1; j <= countMenu; j++){
let num = window["menu"+j];
let div = document.createElement('button');
div.className = "buttonMenu";
div.innerHTML = num.name;
allbody.append(div);
}