Delegated events being lost after one of them actioned
Delegated events being lost after one of them actioned
I have a datatable and each row has a series of links that do something (such as edit the name, archive the record). They are all linked with delegated calls"
$("#folders").on("click", ".editfolder", function (event) {
event.preventDefault();
var table = $("#folders").DataTable();
var row = table.row($(this).parents("tr"));
smxTableDialogForm(this.href, "folders", row);
});
folders is the table Id.
when the edit is complete the data in the table is updated and after the update is done the following is executed
$("#" + tableId).unbind("click");
var table = $("#" + tableId).DataTable();
setTimeout(function () { table.draw(); }, 1500);
However, after this all the events stop working.
I can give you a login to see this in action.
This discussion has been closed.
Answers
ok, I think I've spotted this one - wood and trees
You will probably want to use jQuery .off() to correspond with the
on()
. Maybe like this:$("#" + tableId).off("click", ".editfolder");
Kevin
thanks Kevin. I have just removed the unbind. That is legacy code from when I was binding at a lower level I think, which is not needed now at the table level - time will tell