tags:

views:

35

answers:

1

Hi,

How can I count the total of TD elements before a specific TD ?

var eq = $('td.input.current').prevAll('td.input').length;

eq is the position of the TD that have the class current but this position is relative to his containing TR, in other word prevAll() is only usefull for the TD brothers but not cousins =/

+2  A: 

The following is pretty direct, though it takes two searches. Also, assumes you only care about the current table (no nesting).

var current = $('td.input.current');
var eq = current.prevAll('td.input').length
            + current.closest('tr').prevAll('tr').find('td.input').length;
tvanfosson
Thanks tvanfosson!! =)
adrien334