JQuery - What is the purpose of this syntax $(function () { ... });

javascript, jquery

Solution

Its simply shorthand for:

$(document).ready(function(){

});

http://api.jquery.com/ready/

Problem

I'm working with SignalR, and by extension, JQuery. Some initialisation code runs inside a function block defined with the following syntax: ``` $(function () { // ... Init code here e.g. var hub = $.connection.myHub; }); ``` What is the functional difference here compared with just executing scripts directly within a pair of script tags?

Original source

Related problems