jquery .remove() method doesn't trigger .on('remove') event -
i'm removing html element .remove() method , @ same time element have event handler not triggered. why can be? here jsfiddle , code: html
<span id='del_span'>delete</span><br> <span id='to_del'>i'm going deleted</span>
js
$('#del_span').click(function() { $('#to_del').remove(); }); $('#to_del').on('remove', function() { alert("i'm being deleted"); //is never triggered });
the remove()
method doesn't automatically trigger remove
event (because no such event exists), can manually though, custom event:
$('#del_span').click(function() { $('#to_del').trigger('remove').remove(); }); $('#to_del').on('remove', function() { alert("i'm being deleted"); //is never triggered });
incidentally, in browsers support mutation events use:
$('#del_span').click(function() { $('#to_del').remove(); }); $('body').on('domnoderemoved', '#to_del', function() { alert("i, " + this.id + " being deleted"); });
references:
Comments
Post a Comment