user2620804
user2620804

Reputation: 133

JQuery - Check when slidetoggle is sliding down

$(document).on('click', '.selector', function(event){ 
    var id = $(this).data('id');
    event.stopPropagation();
    var $target = $(event.target);

    $.ajax({
        type: "GET",
        url: "components/display.cfc?method=displayFields&ID=" + id + "&returnformat=plain",
        success: function(html){
            $('.myDiv').append(html);
            if ( $target.closest("td").attr("colspan") > 1 ) {
                $target.slideUp();
            } else {

                $target.closest("tr").next().find("p").slideToggle();
            }           
         },
         error: function(jqXHR,textStatus,errorThrown){
            console.log(textStatus);    
         }
   });      
});

I need to check when the slideToggle is sliding down so I can reset/remove value of html. How is this possible?

Upvotes: 2

Views: 111

Answers (2)

Adjit
Adjit

Reputation: 10305

Slide Toggle has the ability to do a function callback which will happen after the slide animation. This may work for your situation.

Documentation for slide toggle can be read here: http://api.jquery.com/slidetoggle/

Proper usage for your situation:

$(someElement).slideToggle(function(){
    //Any code in here will be executed after the slideToggle function has finished
});

Upvotes: 2

Leo Yukku
Leo Yukku

Reputation: 52

Put a callbackafter the slideToggle() function;

$(document).on('click', '.selector', function(event){ 
    var id = $(this).data('id');  
    event.stopPropagation();
    var $target = $(event.target);

    $.ajax({
        type: "GET",
        url: "components/display.cfc?method=displayFields&ID=" + id + "&returnformat=plain",
        success: function(html){
            $('.myDiv').append(html);
            if ( $target.closest("td").attr("colspan") > 1 ) {
            $target.slideUp();
            } else {

                $target.closest("tr").next().find("p").slideToggle();
                alert("Finished"); // <- callback here
            }           
        },
        error: function(jqXHR,textStatus,errorThrown){
            console.log(textStatus);    
        }
    });   
});

Upvotes: 1

Related Questions