There is an n-th number of buttons created by the loop. In the same place, they are assigned an id and a setClass (id) function. This function changes the color of this button several times:
/* Цикл создающий таблицу из буттонов */ button.setAttribute("id", id); button.setAttribute("onclick", "setColorClass('"+id+"')"); function setColorClass(id) { var elem = document.getElementById(id); if (elem.className == "firstClass") { elem.setAttribute("class", "SecondClass"); } else if (elem.className == "SecondClass") { elem.setAttribute("class", "ThirdClass"); } etc... I need: so that when I click on one button, an attribute with a sequence number is assigned to it. When you click on some other button: the next number and so on. It is impossible that when you click on one and the button, the numbers are moved. One button is the same digit.

var i = 1. When you click on a button, check whether your attribute has an element; if it doesn’t have one, then create it with a value ofi, then add one toi(i++). - mixelem.setAttribute("number", number)- Zhi V