Hi, this is probably really simple for a jQuery expert.
I have <div id="form23"><form><textarea>blahblah</textarea><input type="button" value="save" onClick="saveCaption(23)"></form></div>
I want a SAVED message appear and disappear. But I DO NOT want to make the form or its elements disappear.
I have a AJAX call that is like the following.
function saveCaption(id) {
var queryString = $('#form'+id).formSerialize();
$.ajax({
type: "POST",
url: "includes/ajax.php?request=saveCaption",
data: queryString,
success: function(response) {
$('#form'+id).append(response)
}
});
return false;
}
I was wondering.. I can append the response. But is there a way to fade it out right away after a second. Right now, it just keeps repeating and adding to the last append. I would like it to appear and disappear right after using fadeOut.
UPDATE: I did this based on theIV and RaYell's response. It works.. but is it elegant?
function saveCaption(id) {
var queryString = $('#form'+id).formSerialize();
$.ajax({
type: "POST",
url: "includes/ajax.php?request=saveCaption",
data: queryString,
success: function(response) {
$('#form'+id).append('<div id="message">'+response+'</div>');
setTimeout(function () {
$('#message').fadeOut(function(){
$(this).remove();
});
}, 1000);
}
});
return false;
}