Same problem I tried to solve few days back. You can use this code as a template for similar problems. I will comment on the way.
window.onload = function() {
/* variable stores html data as array for desired tag, this case it's 'tr' -*/
var test = this.test = $('tr');
/* loop traverses the row elements in the array, which element is clicked */
for (var i = 0; i < test.length; i++){
index = Array.prototype.indexOf.call(test,test[i]);
/* it's best to store the index inside the original row element which eases the access */
test[i].setAttribute('index',index);
/* on clicking the element it calls for a function which alerts the index */
test[i].onclick = alertTheClick ;
/* this is in case of debug */
console.log(index);
}
};
/* function definition */
function alertTheClick(index){ /* index value from loop */
alert(this.getAttribute('index')); /* index attribute from 'tr' element */
}
myTable?