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

前端 未结 2 352
暗喜
暗喜 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...
    });
    
    0 讨论(0)
  • 2020-12-03 23:29

    yes, they're doing the same thing. the $() function wraps $(document).ready() when the parameter to the call is a single function object.

    (Edited to reflect a question in comment)

    0 讨论(0)
提交回复
热议问题