10

I need to call a function after a DIV has been removed from the page.

I have tried adding a callback like so, but no luck. Any suggestions?

$(foo).remove( function() {
   stepb();
});
Jason Wells
  • 887
  • 6
  • 16
  • 33

2 Answers2

20

Try this

$.when($('#foo').remove()).then(stepb()); [Example1][1] and [Example2][2].

$('#foo').remove();
stepb();

​Since the remove method in jQuery is synchronous, stepb() will be invoked after remove() has finished. So, no need to use $.when().then().

The Alpha
  • 143,660
  • 29
  • 287
  • 307
0

By default there is no event fired when something is removed from the DOM.

Take a look at this question for some good workarounds: jQuery - Trigger event when an element is removed from the DOM

Community
  • 1
  • 1
Jason Whitted
  • 4,059
  • 1
  • 16
  • 16