I insert dynamically some images used as buttons and add an onClick event.
$("img.image_edit_customer").live("click", function() {
// when clicking the edit image of a row
$(this).manipulateCustomer("editRowCustomer", {
scope : "#customer_tbody"
});
});
Later I want to remove the onClick event from the image used as button.
$('img[class^="image_edit"]').live('click', function() {
// do nothing from now on
alert('edit');
});
Now, it always executes the old and the new handler.
UPDATE
If I’m using die('click');, I can still execute the onCLick event once.
For jQuery 1.7+
To attach an event that runs only once and then removes itself:
To attach an event that can be remove at a later time:
To remove the event:
Function to attach and remove