title: How do I add an onclick event to html tags without id's using javascript?
body: <p>I tried doing this but it didn't seem to work:</p>
  
  <pre><code> window.onload = initAll;
  
  
      function initAll(){
      document.getElementsByTagName('a').onclick = clickHandler;
       }
  
      function clickHandler(){
          if(this.toString().indexOf("localhost") &lt; 0) {
              confirmation = confirm("You are now leaving http://soso.com.  Please click 'ok' to continue to this site, or 'cancel' to stay in http://soso.com");
                  if (confirmation == false){
                      return false;
                  }
  
          }
  
      }
  </code></pre>
  
  <p>I know I can getElementById and that works, but it doesnt work this way.  Any help would be appreciated.</p>
  
  <p>Thanks!</p>