$(function() { $('#filter').each(function() {  var tbody = $(this).parent().next().find('tbody'),   trs = tbody.find('tr'),   tbodyClone = $('<tbody></tbody>'),   trsClone = trs.clone();  tbodyClone.append(trsClone);  $(this).keyup(function() {   var temp = $('<tbody></tbody>'),    currentTh = false,    value = $(this).val().toLowerCase();   trsClone.each(function() {    var tr = $(this);    if (parseInt(this.id) == this.id) {     if (tr.text().toLowerCase().indexOf(value) != -1) {      if (currentTh) {       temp.append(currentTh);       currentTh = false;      }      temp.append(tr);     }    } else {     currentTh = tr;    }   });   tbody.html(temp.html());  }); });});
