I need to dynamically bind() the click event, but the problem is when I bind for the second or third time, last bind()-ed callbacks will also trigger. How can I clear last bind()-ed event callbacks? And overwrite click event with this new callback func?
Note that event is a user-defined object, and not Javascript event object.
function showEditModal(event, callback)
{
$("#dialog-form").dialog('open');
$('#place').val(event.metadata.place);
$('#type').val(event.metadata.type);
$('#city').val(event.metadata.city);
$('#dialog-form .button-save').show().click(function()
{
event.metadata.place = $('#place').val();
event.metadata.type = $('#type').val();
event.metadata.city = $('#city').val();
$('#dialog-form').dialog('close');
callback(event);
});
}
How about using one? This method is identical to .bind(), except that the handler is unbound after its first invocation. (based on jQuery docs)