Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.remove() ignore .delay()?

Tags:

jquery

Here there is an example :

<div id='example'>
    ciao
</div>

$('#example').fadeOut(600).delay(600).remove();

I want to fadeout the element, than remove it, but looks like that .remove() ignore .delay() (so the element is removed immediatly).

How can I fix this trouble?

like image 989
markzzz Avatar asked Feb 27 '26 05:02

markzzz


2 Answers

.remove is not about animating, so .delay has no effect.

What you can do is passing a function which gets executed when the animation has finished (the callback argument - see http://api.jquery.com/fadeOut/):

$('#example').fadeOut(600, function() {
    $(this).remove();
});

http://jsfiddle.net/pimvdb/Sny7P/1/

like image 147
pimvdb Avatar answered Mar 01 '26 19:03

pimvdb


Specify a callback instead

$('#example').fadeOut(600, function() { $(this).remove(); });
like image 33
Dogbert Avatar answered Mar 01 '26 20:03

Dogbert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!