Hi can some one explain to me what is meant by the two following function declarations
$(function() {
});
and
jQuery(function($){
});
Thanks
Hi can some one explain to me what is meant by the two following function declarations
$(function() {
});
and
jQuery(function($){
});
Thanks
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.
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/
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.