If you just want to hide the element instantly, then extinguish it with new text, do the following:
$('#title').hide().text(data.name).fadeIn();
If instead you want it to be animated, your code did not wait for something to happen: it starts to disappear, then it instantly sets the text and then disappears (without waiting for the completion of something).
Use callbacks, which are anonymous functions that are called after the full implementation of the parent function:
$('#title').fadeOut(function() {
$(this).text(data.name).fadeIn();
});
I really want jQuery functions to be able to be constrained so easily ...
Good luck
source
share