How to find the last visible <td> in a table?

I use a table with one row and several <td>inside it, and I use hide / show on tds. Each tdhas a unique id.

Is there any way to recognize the last visible td from this table?

+3
source share
2 answers

Yes, this is pretty trivial with jQuery

$('td:visible:last')

See fiddle

+4
source

In simple Javascript, I think it should be something like this:

var els = document.getElementsByTagname('td');
for (var i = 0 ; i < els.length ; i++)
  if (els[i].style && els[i].style.display != 'none')
    last = els[i];
+1
source

All Articles