tags:

views:

866

answers:

1

i need to find the position of a child element.

i have a table and when a td is clicked, i want the position of the td(0,1 or 2)

<table>
<tr>
 <td>   

 </td>
 <td>   

 </td>
 <td>

 </td>
</tr>
</table>

and a script like this

<script>
$("td").click(function(){
  //how do i get the position of the td?
  alert("collumn " + columnPosition + "is clicked")
});
</script>
+8  A: 
<script>
$("td").click(function(){
  //how do i get the position of the td?
  alert("column " + $(this).parent().children().index(this) + " is clicked")
});
</script>

edit: I tested it, and it works

Thomas Stock