title: Use JavaScript to return correct row number without using inline code
body: <p>Is there a way of using javascript to alert the correct row number, without using "onclick" or "this"  or in fact any javascript in the HTML other than a link to a js page?</p>
  
  <p>This is my HTML
      
  </p>
  
  <p>
  </p>
  
  <p></p>
  
  <pre><code>&lt;div align='center'&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;b&gt;Row Number  &lt;/b&gt;&lt;/td&gt;
              &lt;td&gt;Confirm&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td class='row_num'&gt;100&lt;/td&gt;
              &lt;td&gt;&lt;button class='confirmed'&gt;Confirm&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td class='row_num'&gt;101&lt;/td&gt;
              &lt;td&gt;&lt;button class='confirmed'&gt;Confirm&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td class='row_num'&gt;102&lt;/td&gt;
              &lt;td&gt;&lt;button class='confirmed'&gt;Confirm&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td class='row_num'&gt;103&lt;/td&gt;
              &lt;td&gt;&lt;button class='confirmed'&gt;Confirm&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td class='row_num'&gt;104&lt;/td&gt;
              &lt;td&gt;&lt;button class='confirmed'&gt;Confirm&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;script type="text/javascript"src="js/test.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>
  and here's the javascript. Now I am aware that the code is wrong and why it's wrong. I'm using a for loop that returns every row number. So I put a break in but, this just breaks at the first-row number and alerts 100 on every button. So what I need to know is if it's possible to alert the correct row number without using any inline javascript code in HTML page. </p>
  
  <pre><code>window.onload = addListener();
  
  function buttonClick(){
  
  var x = confirm("Are you sure you want to delete?");
  
  var rowNum = document.getElementsByClassName("row_num");
  
  if (x)
  var y;
  for (y = 0; y &lt; rowNum.length; y++) {
  var nums = rowNum[y].innerText;
      alert(nums + " Has been deleted");
          break;
  }
  else
  return false;
  }
  
  function addListener() {
  var i;
  var z = document.getElementsByClassName("confirmed");
  for (i = 0; i &lt; z.length; ++i){
  z[i].addEventListener("click", buttonClick);
  
  }
  }
  </code></pre>