0

I am trying to run a function once an element has been deleted from the html.

I added

$("selector").on('DOMNodeRemoved',function(){
            //do stuff
        });`

The issue is that while the function in running the element that has been deleted is still there, and is only removed after the function finishes running. Is there a way to run this function after this listener has completed?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • This could be related to your issue: https://stackoverflow.com/questions/2200494/jquery-trigger-event-when-an-element-is-removed-from-the-dom – Fizz Jun 04 '18 at 18:04

1 Answers1

0

could add a short setTimeout so code gets run at end of the event loop

$("selector").on('DOMNodeRemoved',function(){
    setTimeout(function(){
      //do stuff
    },10);               
});
charlietfl
  • 170,828
  • 13
  • 121
  • 150