the location where javascript appears is important (remember browser engine is parsing and executing at the same time). The following didn't work:
var add_the_handlers = function(nodes){
var i;
for (i=0; i
nodes[i].onclick=function(e){
alert(i);
}
}
}
add_the_handlers(document.getElementById('samplelist').children);
Because
- tag appears after the