How to deal with '.live' when data is added/deleted ?

How to deal with '.live' when data is added/deleted ?

southof40southof40 Posts: 4Questions: 0Answers: 0
edited September 2011 in General
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.

Replies

  • GregPGregP Posts: 500Questions: 10Answers: 0
    Richard,

    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]
This discussion has been closed.