When you call index() on that selector, you're in fact getting the index of the a element. The text selector is working fine, but after finding the element with the mached text, you need to find it's tr and get it's index:

In the event function, you can see that you don't need the full selector to the a element, you already have the element, so you can use this to find its tr. In this case you don't need to find the element by it's content as well, the event is being called fron it already.