Different ways of saying document ready in jQuery?

后端 未结 3 767
时光说笑
时光说笑 2021-01-02 16:59

Are these both the same thing, i.e. ways of saying document ready:

$(function() {
  //
});

and

$(function($) {
   //
})(jQ         


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 17:03

    They both are not same.

    First code block is used to execute the function on document ready where as second code block is used when we want to execute the code block immediately without waiting for rest of the code to be loaded. But there is some error in your second part of the code. It should be as below.

    (function($) {
       //
    })(jQuery);
    

提交回复
热议问题