Jquery - Perform callback after append

后端 未结 4 1324
独厮守ぢ
独厮守ぢ 2020-12-15 03:25

I am appending content to a list using:

  $(\'a.ui-icon-cart\').click(function(){
         $(this).closest(\'li\').clone().appendTo(\'#cart ul\');
  });
         


        
4条回答
  •  渐次进展
    2020-12-15 04:24

    In jquery you could use $() just after your appending contents code. This way you can be sure that the content is loaded and the DOM is ready before performing any tasks on the appended content.

    $(function(){
    //code that needs to be executed when DOM is ready, after manipulation
    });
    

    $() calls a function that either registers a DOM-ready callback (if a function is passed to it) or returns elements from the DOM (if a selector string or element is passed to it)

    You can find more here
    difference between $ and $() in jQuery
    http://api.jquery.com/ready/

提交回复
热议问题