Voksin,
<html>
<head>
<script>
function myFunction() {
    var btn, t;
    for (i=0; i < 24; i++) {
        btn=document.createElement("BUTTON");
        t=document.createTextNode("CLICK ME "+i);
        btn.appendChild(t);
        btn.onclick = (function(i){ return function() { alert(i); } })(i);
        document.body.appendChild(btn);
    }
}
</script>
</head>
<body>
<button onclick="myFunction()">Try it</button>
</body>
</html>