Need to write function to alert index of clicked link in the document. For example:
[html]
<body>
Links:<br/>
<a href="//www.yahoo.com">Yahoo!</a><br/>
<a href="//www.facebook.com">Facebook</a><br/>
<a href="//www.google.com">Google</a><br/>
</body>
[/html]
My function:
var as = document.getElementsByTagName('a');
for (i = as.length; i>= 0; i--) {
as[i].onclick = function() {
alert(i);
}
}
Please help me fix bugs