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 }); 

js fiddle demo.

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"); }); 

js fiddle demo.

references:


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -