I am currently studying javascript so if my question is really stupid please excuse me in advance. The main idea behind this function is to take the value of the div on which the user has clicked. However, I am not sure why but no matter which class you click it takes the value of the last div. If someone can explain what I am doing wrong I will be extremely grateful.
Best regards, George
var Get_Class = document.getElementsByClassName("Letter");
for (i = 0; i < Get_Class.length; i++){
var Letter = Get_Class[i];
Letter.onclick = function(){
console.log(Letter.innerHTML);
}
}
<div class="Letter">A</div>
<div class="Letter">B</div>
<div class="Letter">C</div>
<div class="Letter">D</div>
<div class="Letter">E</div>