What is the difference between $(document).ready(function() and $(function() ?

前端 未结 2 360
暗喜
暗喜 2020-12-03 22:58

So I know what this does:

$(document).ready(function(){
    // Your code here...
});

Now I have seen people doing this lately:



        
2条回答
  •  感动是毒
    2020-12-03 23:26

    Yes, they are doing exactly the same thing.

    $(function(){
        // Your code here...
    });
    

    is a shortcut for

    $(document).ready(function(){
        // Your code here...
    });
    

提交回复
热议问题