I would like to get the last visible td
in each tr
in a table.
This does not work because it attempts to select the last child if it is visible:
var last_visible_cells = $(table).find("tr td:visible:last-child");
So far the simplest method I've thought of is to use a .each
to loop through the tr
elements and append each of the last visible td
s to a new selector list.
Is there a simpler way? Does anything like this exist?
var last_visible_cells = $(table).find("tr").lastMatching("td:visible");
You can do it:
See a full example (jQuery 1.2+ compatible)
to get every last visible them you can do something like
Based on the answer from Mathletics, but using
nextUntil()
. This finds each visible tag that doesn't have a following visible tag.You want to grab all the TDs and filter for only the ones that don't have a visible element next to it.Dang, that only works if there aren't any invisibles in the middle of the row.