What will the console log output be, when the corresponding the button of 'button 5' is clicked?
The answer is clicked button 10 but not clicked button 5 , why??
Please help me solve the problem
for (var i = 0; i < 10; i++) {
let button = document.createElement("button");
button.textContent = "button " + i;
button.onclick = function() {
console.log("clicked button " + i);
};
document.body.append(button);
}