for (i = 0; i < array.length; i++) {
$("#results").on("click", "#source_" + array[i], function(event) {
event.preventDefault();
alert('i : ' + i); // here i equal table.length, always
});
}
Imagine the <div id="results">
has been triggered by a previous javascript action.
If array.lenght = 10, and if I click on <element id="source_5">
, the function alerts 10
.
How to get the array value of the clicked element, 5
in this example ?