Kamil Jarząb
Kamil Jarząb

Reputation: 53

How to run code when jquery slideUp() finished?

is there any way to execute html(), only when slideUp() will be finished?

<p class="test">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tortor elit</p>
$(".test").slideUp().html("");

I tried did it with Deferred and queue, but I failed.

Upvotes: 2

Views: 64

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115242

Do it within the animation complete callback.

$(".test").slideUp(function(){ 
  $(this).html(""); 
});

$(".test").slideUp(2000,function() {
  $(this).html("");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="test">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tortor elit</p>

Upvotes: 5

Related Questions