jQuery function after .append

后端 未结 19 2440
栀梦
栀梦 2020-11-27 15:25

How to call a function after jQuery .append is completely done?

Here\'s an example:

$(\"#root\").append(child, function(){
   // Action          


        
19条回答
  •  无人及你
    2020-11-27 15:45

    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 .append method 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 .append will be run synchronously.

提交回复
热议问题