$ (Function () {...}) in javascript (){....}) is a classic usage in jQuery, equivalent to $ (document ). ready (function (){....}) $ (function () {}) in javascript; What are the differences between writing and not writing? For more information, see
$ (Function () {...}) in javascript (){....})Is a classic usage in jQuery, equivalent
$ (Document). ready (function (){....}),That is to say, a function is executed only after the page is loaded. If you want to operate DOM in the function, it is safer to execute the function after the page is loaded. Therefore, this method is common when using jQuery.
$ (Document). ready ()The code in is executed only after the page content is loaded. If you write the code directly to the script tag, the code will be executed after the script tag is loaded on the page, if the code executed in your tag calls the code or dom that has not been loaded yet, an error is reported, of course, if you put the script tag at the end of the page, there will be no problem. This is the same as ready.
$ (Document). ready (function () {}) can be abbreviated to $ (function (){});
After clicking a paragraph, this paragraph is hidden: