Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 858
gb2d Avatar asked Mar 19 '13 14:03

gb2d


1 Answers

Its simply shorthand for:

$(document).ready(function(){

});

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

like image 120
Curtis Avatar answered Sep 30 '22 20:09

Curtis