My question is simple but little bit confusing for me that when we write code of document.onclick
with function function(e)
so why we put e
into parameter even though function is not return anything in call back function's paramter because it's anonymous function so my point is that why we don't put e
or event
inside the function instead of parameter().
var divs = document.getElementsByTagName('div');
for(var i =0; i<divs.length; i++){
divs[i].onclick = function(e){
e = e || event;
var target = e.target || e.srcElement;
this.style.backgroundColor='yellow'
e.stopPropagation();
alert("Target " + target.className + ",this " + this.className);
}
}