-8

Hi can some one explain to me what is meant by the two following function declarations

$(function() {

});

and

jQuery(function($){ 

});

Thanks

zzlalani
  • 22,960
  • 16
  • 44
  • 73
user2429569
  • 91
  • 2
  • 8

3 Answers3

2

Take a look at the API docs here: http://api.jquery.com/jQuery/#jQuery3

$(function(){}) and jQuery(function(){}) are, for most practical purposes, the same thing. $ is a kind of an "alias" for jQuery. Whenever you pass a function as the first argument into $() or jQuery(), it will call that function when the DOM is ready.

Divey
  • 1,699
  • 1
  • 12
  • 22
1

I think this would be best explained by Paul Irish in the 10 Things I Learnt From JQuery Source video he made.

He not only covers your question, but various other points - well worth a watch!!

http://www.paulirish.com/2010/10-things-i-learned-from-the-jquery-source/

Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89
0

It's pretty much like the document.onload: the script will be executed when everything has been load.
It's very useful when you do some DOM manipulation.

Binary Brain
  • 1,170
  • 8
  • 20
  • Not specifically true - document.onload and document.onready are slightly different... http://stackoverflow.com/questions/3698200/window-onload-vs-document-ready – Stuart.Sklinar Nov 08 '13 at 10:32