[ACCEPTED]-jQuery slideUp().remove() doesn't seem to show the slideUp animation before remove occurs-animation

Accepted answer
Score: 206

Might be able to fix it by putting the call 2 to remove in a callback arg to slideUp?

e.g 1

selectedLi.slideUp("normal", function() { $(this).remove(); } );
Score: 22

You need to be more explicit: rather than 2 saying "this" (which I agree should work), you 1 should do this:

$("#yourdiv").slideUp(1000, function() {
Score: 8

The simplest way is calling the "remove()" function 8 inside slideUp as a parameter like others 7 have said, as this example:

$("#yourdiv").slideUp("normal", function() {

It is a must 6 to call it inside the anonymous function() to 5 prevent remove() to be executed before the 4 slideUp has ended. Another equal way is 3 to use the jQuery function "promise()". Better 2 for those who like self-explanatory code, like 1 me ;)

$("#yourdiv").slideUp("normal").promise().done(function() {
Score: 4

Using promises you can also wait for multiple 1 animations to get finished, e.g.:

selectedLi.slideUp({duration: 5000, queue: false})
.fadeOut({duration: 3000, queue: false})
.promise().done(function() {

More Related questions