I have got a quick noob question: I am trying to retrieve the values of an array and printing them to an html element with jQuery "on Click". However, I cannot seem to retrieve the array elements. For each clicked item it should get the array element at index i , so #item-0 should get the value of "red", etc.
The console logs undefined.
var descriptions = ["red", "blue", "green", "purple", "white", "black"];
for (var i = 0; i < descriptions.length; i++) {
$("#item-" + i).on("click", function() {
var currentDescr = descriptions[i];
console.log(currentDescr);
$("#footer-text").html(currentDescr);
});
};
.as-console-wrapper{top:0;max-height:100%;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Any help would be appreciated.
clossureorlet(let i = 0;)undefined"? I can't see anyconsole.logstatements in your code.