I have a hard time adding events to object and array So:
-i created divs using createElement, added the same class using FOR loop and then appendChild to some other html TAG
-i want to addEvennt to divs and i want to pass unique variables(i from FOR loop)
-it returns i max value; or error or does nothing at all
THX for any kind of answer :D
i know this is simple question but i can't find answer to this anywhere
window.onload = function (){
var sectionHTML = document.getElementById('section');
for(i=0;i<5;i++)
{
var div_box = document.createElement('div');
div_box.className = "box";
div_box.innerText=i;
sectionHTML.appendChild(div_box);
}
//adding Events
var getDIV = document.getElementsByClassName('box');
for(i=0;i<5;i++)
{
getDiv[i].addEventListiner("click", function (i) { myFunction(i); })
}
}
myFunction (i) {
var myString = "PLS HELP THX BRO or SIS " + i;
alert(myString);
}