开发者

Getting column number from td

开发者 https://www.devze.com 2023-02-11 02:45 出处:网络
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.

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 f开发者_高级运维or:

('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);

});


You can use the index() function.

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


The cellIndex property returns the position of a cell in the cells collection of a table row. w3schools

 td.cellIndex 

demo

0

精彩评论

暂无评论...
验证码 换一张
取 消