markzzz
markzzz

Reputation: 47995

.remove() ignore .delay()?

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?

Upvotes: 2

Views: 204

Answers (3)

alexn
alexn

Reputation: 59002

Instead of using delay, pass a callback to fadeOut:

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

Upvotes: 3

Dogbert
Dogbert

Reputation: 222358

Specify a callback instead

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

Upvotes: 4

pimvdb
pimvdb

Reputation: 154918

.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/

Upvotes: 6

Related Questions