admin管理员组文章数量:1202959
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();
});
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();
});
Share
Improve this question
asked Dec 31, 2012 at 20:21
Jason WellsJason Wells
8896 gold badges16 silver badges33 bronze badges
5
|
2 Answers
Reset to default 20Try 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()
.
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
本文标签: javascriptjQuery callback within the remove() functionStack Overflow
版权声明:本文标题:javascript - jQuery callback within the remove() function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738662214a2105492.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
remove().done(function(){ stepb() });
– mplungjan Commented Dec 31, 2012 at 20:24$(foo).remove(); stepb();
? It is an issue with the context ofstepb()
? – Jonathan Lonowski Commented Dec 31, 2012 at 20:34.remove()
is a synchronous operation. The elements will already be detached from thedocument
when itreturn
s and beforestepb()
is called. – Jonathan Lonowski Commented Jan 1, 2013 at 7:48