I have a table that is being dynamically repopulated by an ajax call.
I also have a keyup event which filters the table rows based on the user input:
$('input#DocumentType').keyup(function () { filter rows });
But when I repopulate the table from an ajax call, the filter no longer works. Is there a way to circumvent this so that I am able to use the keyup event? Is it possible to rebind this every time the table rows change from the ajax call?
Here is how I am filtering:
<script type="text/javascript">
var $cellsT = $("table tbody tr td:nth-child(4)"),
$hiddenT = $();
$("input#DocumentType").keyup(function () {
var search = $(this).val();
var $to_hide = $cellsT
.filter(function () {
var s = $(this).text().indexOf(search) === -1;
if (s === false) {
foundDocuments = true;
}
return $(this).text().indexOf(search) === -1;
})
.parent();
$hiddenT.not($to_hide.get()).show();
$hiddenT = $to_hide.hide();
});
</script>
You could do
$('input#DocumentType').live("click",function(){});Also in latest version of jQuery its preferred to use
.on()and.off()instead oflive()anddie()