jQuery function after .append

后端 未结 19 2399
栀梦
栀梦 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:42

    Although Marcus Ekwall is absolutely right about the synchronicity of append, I have also found that in odd situations sometimes the DOM isn't completely rendered by the browser when the next line of code runs.

    In this scenario then shadowdiver solutions is along the correct lines - with using .ready - however it is a lot tidier to chain the call to your original append.

    $('#root')
      .append(html)
      .ready(function () {
        // enter code here
      });
    

提交回复
热议问题