Ricardo Zea
Ricardo Zea

Reputation: 10283

jQuery: callback doesn't work right

I'm new to jQuery so forgive me (and correct me too please) if I say something wrong here.

I have this code and the callback is being executed right the moment the element is clicked, and not after the slideUp has finished:

$('.close-button').click(function(){
    $('.click-menu div').slideUp(3000, function() {
        $('.generic-box a, .generic-box p').css('z-index','1');
    });     
});

Am I missing something?

Any help would be greatly appreciated.

Thanks.

Upvotes: 2

Views: 523

Answers (2)

Jean-nicolas
Jean-nicolas

Reputation: 51

No the callback call once the animation is complete

you can use the jquery documentation it's realy helpful

http://api.jquery.com/slideUp/

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630409

What's likely happening is that any already hidden <div> elements will execute the callback immediately, since their animations to hide are complete immediately, you can avoid this by only sliding up :visible elements, like this:

$('.close-button').click(function(){
    $('.click-menu div:visible').slideUp(3000, function() {
        $('.generic-box a, .generic-box p').css('z-index','1');
    });     
});

Upvotes: 7

Related Questions