JQuery delete DOM element after fading out

大憨熊 提交于 2019-12-03 04:12:02

问题


I want to delete an DOM element right after fading out. What I did so far is

$(element).click(function()
{
    $(this).fadeOut(500, function() { $().remove(this); });
});

But now I always get this error in Firebug: http://dl.getdropbox.com/u/5912/Jing/2009-02-04_1109.png

I guess it is because the fadeOut function is not really done when the callback gets called. And I can not put the $.remove() part after the fadeOut call because otherwise it gets removed instantly.

So do you know of any way I can do this better?


回答1:


You're using the remove() function wrongly.

$(element).click(function() {
    $(this).fadeOut(500, function() { $(this).remove(); });
});



回答2:


See this earlier SO question.




回答3:


why messing here just use $('#anydiv').remove();




回答4:


or $.remove($(this));



来源:https://stackoverflow.com/questions/510761/jquery-delete-dom-element-after-fading-out

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!