JQuery: is there a way to run a function once an Event Listener is finished

时间:2018-06-04 17:29:38

标签: javascript jquery javascript-events

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?

1 个答案:

答案 0 :(得分: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);               
});