$('tr[id=food-<%= @food.id %>]').nextUntil('tr.primary', ':not(.food)') .remove(); var columns = $('table > thead > tr > th').length; $('tr[id=food-<%= @food.id %>]').nextUntil('tr.primary').addBack().last().after( '