I have come up with the code below. The problem is that on change every element alerts the last iteration index. For example if there are 24 items on the elements array every single element on change will alert "Changed row 23" . I kind of see why it is happening but cant find away to get around it so that every element onchange will alert its index instead of the last. Any help will be appreciated.
for (var i = 1; i < elements.length; i++) {
elements[i].onchange = (ev: Event) => alert("Changed row " + i);
usersTable.appendChild(elements[i]);
}