简体   繁体   English

淡出后,JQuery删除DOM元素

[英]JQuery delete DOM element after fading out

I want to delete an DOM element right after fading out. 我希望在淡出后立即删除一个DOM元素。 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 但现在我总是在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. 我想这是因为调用回调时fadeOut函数并没有真正完成。 And I can not put the $.remove() part after the fadeOut call because otherwise it gets removed instantly. 并且我不能在fadeOut调用之后放置$.remove()部分,否则它会立即被删除。

So do you know of any way I can do this better? 所以你知道我能做得更好吗?

You're using the remove() function wrongly. 你错误地使用了remove()函数。

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

请参阅此前的 SO问题。

为什么搞乱这里只是使用$('#anydiv')。remove();

或$ .remove($(this));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM