$ (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 a friend in need, refer to $ (function () {...}) in javascript (){....}) is a classic usage in jQuery, equivalent to $ (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 ). the code in ready () is executed only after the page content is loaded. If you directly write the code to the script tag, after the script tag is loaded on the page, the code in it will be executed. If the code executed in your tag calls the code or dom that has not been loaded yet, an error will be 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: