On Dec 3, 2007, at 6:42 PM, Larry Reynolds wrote:


What's the best way to find the last non-empty row in a table?

"non-empty" = at least one table cell in the row contains text

Is there a better way than this?

var last = 0;
$("#table1 tr)".each(function(i) {
   if ($(this).children("td:not(:empty)").size() > 0) {
       last = i;
   }
});

Thanks!

Hi Larry,

I don't know if this is necessarily better, but you could use the .text() method on each row, since it concatenates the text from all elements within the row.

var last = 0;
$("#table1 tr").each(function(i) {
   if ($(this).text() ) {
       last = i;
   }
});

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com

Reply via email to