$(document).ready(function() { ... }); it simply associates this function with the finished event of the document, therefore, as you said, when the document is loaded, the event is fired.
(function($) { ... })(jQuery);
is actually a Javascript construct, and all this part of the code passes the jQuery object to the ($) function as a parameter and runs the function, so inside this function $ always refers to the jQuery object. This can help resolve name conflicts, etc.
So, # 1 is executed when the document is loaded, and # 2 is launched immediately, with a jQuery object named $ as an abbreviation
$(document).ready(function(){ ... }); or short $(function(){...});
This function is called when the DOM is ready, which means you can start asking for items, for example..ready () will use different methods in different browsers to make sure the DOM is really ready.
(function(){ ... })();
This is nothing more than a function that activates itself as soon as possible when the browser interprets your ecma- / javascript. Therefore, it is very unlikely that you can successfully act on the DOM elements here.
jQuery document.ready and anonymous anonymous function
Abdul wakeel
source share