I have an array. I am getting data from Array and using it in jQuery Append to list. But when I am clicking on list item its only showing the last element.
var array = [[1,2,7],[3,4,8],[5,6,9]];
for (var i = 0; i < array.length; i++){
var firstVal = array[i].[0];
var secondVal = array[i].[1];
var thirdVal = array[i].[2];
var list = "<div class='divClass' <p class='class1'>"+ firstVal +"</p>"
+ "<p class='class2'>"+ secondVal +"</p></div>";
$("#myDiv").append(list);
$(".divClass").on('click', function(){
alert(thirdVal);
})
}
When I am clicking on each item it always shows the last value of thirdVal
that is 9. How can I get the Third value dynamically?