Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting column number from td

Writing an extension for tablesorter.. though its my first attempt at extending any js. I have a number of <select>s within a row of <td>s & need to know the column this td sits in.

When a value is changed in any of these selects e.g.

$('select').change(function(){

});

I need to get hold of the column this select is sitting in to set col for:

('tr.result > td:nth-child('+col+')').each(function(){

Is there a way I can get this from the td select is in?!?

-- solution for my specific problem was:

$('select').change(function(){

    td  = $(this).parent('td');

    col = $(td).parent().children().index(td);

});
like image 298
null Avatar asked Feb 15 '11 13:02

null


1 Answers

You can use the index() function.

col = $(this).parent().children().index($(this));
like image 84
ReFocus Avatar answered Oct 26 '22 17:10

ReFocus