How to code a javvascript to indicate item in a list clicked? : This javascript fails to show the line number of item clicked.

 

       <!DOCTYPE html>
        <html>
        <body>
        <script>
        function registerHandlers() {
          var as = document.getElementsByTagName('a');
          for (var i = 0; i < as.length; i++) {
            as[i].onclick = function() {
              alert(i);
              return true;
            }
          }
        }
        </script>
        
          In my life, I used the following web search engines:<br/>
          <a href="//www.yahoo.com">Yahoo!</a><br/>
          <a href="//www.altavista.com">AltaVista</a><br/>
          <a href="//www.google.com">Google</a><br/>
        
        
        
        </body>
        </html>