Viktor
Viktor

Reputation: 182

Chaining and Callback Syntax

I am trying to understand the chaining and callback functions, but it seems I am missing something, since the code below does not work and stops before slideDown.

I would like to change the color of a paragraph to red when clicking on a button and then change the color to blue before initiating the fadeOut. Here is my code, based on a W3Schools Tryit Example;

  $("button").click(function(){
    $("#p1").css("color", "red")
      .slideUp(2000)
      .slideDown(2000,css("color", "blue"))
      .fadeOut(2000);
  });

What is the proper way of doing the above?

Upvotes: 1

Views: 60

Answers (1)

tom
tom

Reputation: 10601

The .css method should be in a callback of .slideDown

$("button").click(function () {
  $("#p1").css("color", "red")
    .slideUp(2000)
    .slideDown(2000, function () {
      $(this).css("color", "blue")
    })
    .fadeOut(2000);
});

Upvotes: 2

Related Questions