Delete dynamically-generated table row using jQuery
You need to use event delegation because those buttons don't exist on load:
http://jsfiddle.net/isherwood/Z7fG7/1/
$(document).on('click', 'button.removebutton', function () { // <-- changes
alert("aa");
$(this).closest('tr').remove();
return false;
});
When cloning, by default it will not clone the events. The added rows do not have an event handler attached to them. If you call clone(true)
then it should handle them as well.
http://api.jquery.com/clone/
You should use Event Delegation, because of the fact that you are creating dynamic rows.
$(document).on('click','button.removebutton', function() {
alert("aa");
$(this).closest('tr').remove();
return false;
});
Live Demo