Reputation: 8151
A javascript function has reference to the element that it was called from via the "this" keyword.
In my case the element is a TD
I want to know which number child element that this TD is of the parent TR
How do I do that in jQuery?
I am using version 1.7.1
For example:
<tr>
<td onclick="hasBeenClicked()"></td>
<td onclick="hasBeenClicked()"></td>
<td onclick="hasBeenClicked()"></td>
</tr>
function hasBeenClicked()
{
var childNumber = $(this)....
}
Upvotes: 0
Views: 44
Reputation: 57095
Try using .index()
Index starts from 0
$(this).index();
or
$(this).index('td');
Upvotes: 2