In Html file,I have many statements like this :
<li class="menu"><a href="#">1st menu</a></li>
And in javascript file,I have code like this :
1. function onload()
2. {
3. var lists=document.getElementsByTagName("li");
4. for(var i=0;i<lists.length;i++){
5. if(lists[i].className=="menu"){
6. lists[i].a.onclick=genmenu;
7. }
8. }
9. }
function genmenu(){
alert("this is an alert");
return false;
}
Problem is, if i click on the link '1st menu', it doesn't show alert. But if i change the line 6 and write:
lists[i].onclick=genmenu;
Then this link works and show alert.
My Question, Why line 6 (lists[i].a.onclick=genmenu;) does'nt work? Isn't it a valid code?