title: How to detect which row [ tr ] is clicked?
body: <p>In javascript, how can we detect which row of the table is clicked? At present what i am doing is, i am binding the the method at run time like this. </p>
  
  <pre><code>onload = function() {
      if (!document.getElementsByTagName || !document.createTextNode) return;
      var rows = document.getElementById('my_table').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
      for (i = 0; i &lt; rows.length; i++) {
          rows[i].onclick = function() {
              alert(this.rowIndex + 1);
          }
      }
  }
  </code></pre>
  
  <p>[ copied from [ <a href="http://webdesign.maratz.com/lab/row_index/" rel="nofollow noreferrer">http://webdesign.maratz.com/lab/row_index/</a> ] ]</p>
  
  <p>But i don't like this approach. Is there any alternative? My problem is just to get the index of the row which is clicked.</p>
  
  <ul>
  <li>No jQuery please :D.</li>
  </ul>