alpha
alpha

Reputation: 501

Finding the previous row that is not hidden in Jquery

can someone help me find the previous row that is not hidden. Using the arrow keys, one can navigate up in the cells of table using this.

$(ct).closest('tr').prev().find('td:eq(' + $(ct).closest('td').index() + ')');

I basically get a reference to that cell and set a dark border around it.

Users can show/hide rows. So if the row(s) are hidden, the whole row's display is set to none. If one is navigating up the rows and the next three rows above it are hidden, I need to jump to the one above those three that are not hidden, if that makes any sense.

I've tried:

 $(ct).closest('tr').prev().not(':hidden').find('td:eq(' + $(ct).closest('td').index() + ')');
 $(ct).closest('tr').not(':hidden').prev().find('td:eq(' + $(ct).closest('td').index() + ')');

Both aren't really working. Any ideas? Thanks in advance.

Upvotes: 1

Views: 365

Answers (1)

Musa
Musa

Reputation: 97672

Try

$(ct).closest('tr').
      prevAll(':visible').
      eq(0).
      find('td:eq(' + $(ct).closest('td').index() + ')');

Upvotes: 1

Related Questions