After an Ajax result I'm trying to fadeOut a html button. This works most of the time, however sometimes the button isn't faded out and I can't figure out why.
$.ajax({
type: frm.attr('method'),
url: frm.attr('action')+'?time='+timestamp,
data: frm.serialize(),
dataType: 'json',
success: function (data) {
if(data['success'] === true){
hideSaveButton();
}
}
});
function hideSaveButton(){
$('#saveBtn').fadeOut(250);
}
Accessing the hideSaveButton() function doesn't seem to be a problem. It's just the fadeOut() function that isn't working. I tried replacing fadeOut() by hide() which works without any problem.
Any ideas?
It seems that the calls are being made in quick succession. Which means that the fadeOut
fires before the earlier one has finished.
You may want to stop()
before you attempt the fadeOut()
:
$('#saveBtn').stop().fadeOut(250);
More info: http://api.jquery.com/stop/