Reputation: 133
$(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
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
Reputation: 52
Put a callback
after 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