How to get row index of nested table in html

for click i want to row index of nested element
function editstudent(element) {
var table = document.getElementById("123");
var index = element.closest('tr').rowIndex;
var id = table.rows[parseInt(index)].cells[1].innerHTML;
alert(id);
}
i uesd this code it work but every time it show first row index
suppoe i collapse second row then it give me the row index of upper row not current row
i used this link