//Method-1:
var items = document.getElementsByTagName(‘li‘);
for(var i=0;i<items.length;i++){
items[i].index = i;
items[i].onclick = function(){
this.innerhtml = this.index;
}
}
//Method-2:
var items = document.getElementsByTagName(‘li‘);
for(var i = 0; i<items.length; i++){
(function(index){
items[i].onclick = function(){
this.innerHTML = index;
}
})(i)
}
//Method-3:
var items = document.getElementsByTagName(‘li‘);
for(var i = 0; i<items.length; i++){
items[i].onclick = function(index){
return function(){
this.innerHTML = index;
}
}(i)
}