40

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?

Eddie
  • 53,828
  • 22
  • 125
  • 145
Sebastian Hoitz
  • 9,343
  • 13
  • 61
  • 77

3 Answers3

109

You're using the remove() function wrongly.

$(element).click(function() {
    $(this).fadeOut(500, function() { $(this).remove(); });
});
Georg Schölly
  • 124,188
  • 49
  • 220
  • 267
2

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

Shahid Karimi
  • 4,096
  • 17
  • 62
  • 104
0

or $.remove($(this));

eyurdakul
  • 894
  • 2
  • 12
  • 29