So I'm currently busy with learning JavaScript. I created some dynamic buttons and I tried to add an addEvenListener to it. But it doesn't work and I can't figure it out why it doesn't work. I'm just testing some stuff and I try to create buttons with values from the localstorage. It is almost working, only the addEvenListener isn't working. I just want a simple alert with the key from the localstorage.
for (var i = 0; i <= localStorage.length-1; i++) {
var categoryButton = document.createElement('input');
categoryButton.setAttribute('class', 'forumMenu');
categoryButton.setAttribute('type', 'button');
categoryButton.setAttribute('name', localStorage.key(i));
categoryButton.setAttribute('value', localStorage.key(i));
categoryButton.setAttribute('id', localStorage.key(i));
categoryButton.addEventListener('click', function(col){
alert(col);
}(localStorage.key(i)),true);
forumMenu.appendChild(categoryButton);
}
Does anyone know why it doesn't work?