I am trying to get the index of the clicked element. There are several buttons with the same class name, and I am getting all the elements with:
var button = document.getElementsByClassName("unLockUser-button");
Result of getting all the elements with the same class name:
Now I need to get the index of the selected element, for that I am trying to iterate through the collection, but it is not working:
for (var i = 0; i < button.length; i++) {
button[i].addEventListener("click", () => {
alert(i);
})
}
But as a result, I am getting all the time the same number it does not matter which button that has the same class name I click.