Jquery will not wait for the animation to complete before deletion, why?

I worked on something simple, and not just:

$(this).next().remove();

I wanted it to have a little more flash, and I wanted to add an animation function

$(this).next().slideUp().remove();

where it will slide to hide the item before deleting it. By testing it with Chrome, it pretty much just removes the items and doesn't perform the smoothed transition I was expecting.

Testing without deletion has elements using the slideUp () function.

Is there something I am missing?

+5
source share
3 answers

Try the callback function . slideUp()

$(this).next().slideUp(function() {
  // remove the element after 
  // animation finished
  $(this).remove();
});
+7
source

, slideUp . , , .

$(this).next().slideUp(function(){
    $(this).remove();
});
+4

The animation call is asynchronous as it starts, but execution continues. The way to accomplish what you want with a callback might be as follows:

 $(this).next().slideUp(function(){
     $(this).remove();
    });
+2
source

All Articles