var $theTable = $("table#myTable"), lookAt = ["tr:first-child", "tr:last-child", "td:first-child", "td:last-child"]; for (var i=0; i<lookAt.length; i++) { while ( $.trim($(lookAt[i], $theTable).text()) == "" ) { $(lookAt[i], $theTable).remove(); } }
EDIT: you can use this as an inner loop, maybe this is a little faster:
for (var i=0; i<lookAt.length; i++) { while ( var $x = $(lookAt[i], $theTable), $.trim($x.text()) == "" ) { $x.remove(); } }
source share