jQuery newbie: what does jQuery(function($) { … }) means?

后端 未结 5 1531
旧时难觅i
旧时难觅i 2020-12-13 14:11

I know in jQuery, $(callback) is the same as jQuery(callback) which has the same effect as $(document).ready().

How about

5条回答
  •  一生所求
    2020-12-13 14:44

    • $(function()) is a syntax error.
    • $() creates an empty jQuery object.
    • $(document).ready(function() { ... }) executes the given function when the DOM is ready
    • $(function() { ... }) is a shortcut for the same thing
    • jQuery(function($) { ... }) does so, too, but it also makes $ available inside the function no matter what it's set to outside.

提交回复
热议问题