How to call a function after jQuery .append is completely done?
Here’s an example:
$("#root").append(child, function(){
// Action after append is completly done
});
The issue: When a complex DOM structure is appended, calculation of new size of the root element within the append function callback is wrong. Assumptions are that the DOM in still not completely loaded, only the first child of the added complex DOM is.
You’ve got many valid answers in here but none of them really tells you why it works as it does.
In JavaScript commands are executed one at a time, synchronously in the order they come, unless you explicitly tell them to be asynchronous by using a timeout or interval.
This means that your
.appendmethod will be executed and nothing else (disregarding any potential timeouts or intervals that may exist) will execute until that method have finished its job.To summarize, there’s no need for a callback since
.appendwill be run synchronously.