tags:

views:

1950

answers:

3

I am sure I read about this the other day but I can't seem to find where. I have a fadeOut event after which I remove the element and JQuery is removing the elemnt before it has a chance to finish fading out. What is the solution to this again?

+18  A: 

You can specify a callback function:

$(selector).fadeOut('slow', function() {
    // will be called when the element finishes fading out
    // if selector matches multiple elements it will be called once for each
});

Documentation here.

Paolo Bergantino
Paolo, you would have won the Quick-Draw badge ;) http://meta.stackoverflow.com/questions/1289/new-badge-quick-draw
Jonathan Sampson
Bingo. I thought it was that but what I needed to do was put my entire function in there not just the remove part. P.S. If any one is interested the book I read it in and have now found again is Learning JQuery - Better Interaction and Design. Thanks again
uriDium
@Jonathan: better make sure that gets implemented retroactively. :) @uriDium: Glad it helped.
Paolo Bergantino
A: 

not working, still plays both animations at the same time.

heres code:

$('a#cl-snp').click(function() {
    $('.portItem').fadeOut('400', function() {
      $('#snp').fadeIn('400');
      return false;
    });
});
Luke
A: 

if its something you wish to switch, fading one out and fading another in the same place, you can place a {position:absolute} attribute on the divs, so both the animations play on top of one another, and you don't have to wait for one animation to be over before starting up the next.

Samin