How to deal with '.live' when data is added/deleted ?
How to deal with '.live' when data is added/deleted ?
Hi - I've got a table and I use .live to associate a click event with each row like this :
[code]
$('#tblAAA tbody tr').live('click', function () {
var aData = oTable.fnGetData(this);
var AAAId = aData[0];
$('#spanHDNAAAID input').val(AAAId);
PopulateAAAForm(AAAId);
var frmAAA = $('#dialog-form');
$('#dialog-form').dialog('open');
jQuery("#dialog-form").dialog('option', 'position', 'center');
});
[/code]
When I need to refresh the contents of the table I do a .clear followed by a .update .
Will the .clear remove all the events defined by the previous .live calls or do I need to do this myself in some way ?
Is there anything else I should do to clear down and repopulate an existing table in an optimal fashion ?
Thanks
Richard.
[code]
$('#tblAAA tbody tr').live('click', function () {
var aData = oTable.fnGetData(this);
var AAAId = aData[0];
$('#spanHDNAAAID input').val(AAAId);
PopulateAAAForm(AAAId);
var frmAAA = $('#dialog-form');
$('#dialog-form').dialog('open');
jQuery("#dialog-form").dialog('option', 'position', 'center');
});
[/code]
When I need to refresh the contents of the table I do a .clear followed by a .update .
Will the .clear remove all the events defined by the previous .live calls or do I need to do this myself in some way ?
Is there anything else I should do to clear down and repopulate an existing table in an optimal fashion ?
Thanks
Richard.
This discussion has been closed.
Replies
Give it a go, but my understanding of the .live() function is that should not remove the event listener, as long as the new target selector remains the same.
However, if that doesn't work there is always the delegate function. Assuming #tblAAA itself never actually gets destroyed, the live binding simply becomes:
[code]
$('#tblAAA').delegate('tr', 'click', function() { ... });
[/code]