tags:

views:

344

answers:

1

for example:

<table>
<tr><td>1,1</td><td>2,1</td></tr>
<tr><td>2,1</td><td>2,2</td></tr>
</table>

I wanna using the following function:

$("td").click(function(){
alert(xxxx)
})

to get the <td> `s position when clicked, but how? Thanks.

+6  A: 

Core / index

$("td").click(function(){

    var column = $(this).parent().children().index(this);
    var row = $(this).parent().parent().children().index(this.parentNode);

    alert([column, ',', row].join(''));
})
Alexander Gyoshev
I tried and it worked,thank you very much.:)
milk
You could mark it as an answer, then :)
Alexander Gyoshev
And of course, I'm glad it worked for you :)
Alexander Gyoshev