This sets the last row of cells to the correct height ( demo ):
function grow(td) { var table, target, high, low, mid; td = $(td); table = td.closest('table'); target = table.height(); low = td.height(); // find initial high high = low; while (table.height() <= target) { td.height(high *= 2); } // binary search! while (low + 1 < high) { mid = low + Math.floor((high - low) / 2); td.height(mid); if (table.height() > target) { high = mid; } else { low = mid; } } td.height(low); } $('tr:last-child td').each(function() { grow(this); });
It must be trivial to convert this to plain JavaScript.
Update:. For more complex tables, you will need to replace the last row with this ( demo )
$.each($('td').get().reverse(), function() { grow(this); });
The idea is to call grow()
in each cell, starting from the last row and working up.
source share