Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery delete DOM element after fading out

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?

like image 422
Sebastian Hoitz Avatar asked Feb 04 '09 10:02

Sebastian Hoitz


2 Answers

You're using the remove() function wrongly.

$(element).click(function() {     $(this).fadeOut(500, function() { $(this).remove(); }); }); 
like image 140
Georg Schölly Avatar answered Oct 03 '22 19:10

Georg Schölly


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

like image 29
Shahid Karimi Avatar answered Oct 03 '22 19:10

Shahid Karimi