Alex
Alex

Reputation: 97

jQuery slideToggle - callback function on slideUp action only

Does anyone know a good way to fire a callback function on the slideUp event only during a slideToggle? The default callback function fires on both slideUp and slideDown.

Thanks!

Upvotes: 5

Views: 5657

Answers (1)

Nick Craver
Nick Craver

Reputation: 630429

You can check if the element .is() :hidden since it'll be hidden at the end of a slide up, like this:

$(this).slideToggle(function() {
  if($(this).is(":hidden")) {
    alert("this was a slide up");
  }
});

You can test it out here.

Upvotes: 17

Related Questions