What is the use of writing a jQuery function like so...
$(function myFunction() {
...
});
What i mean is why wrap the function in $
What is the use of writing a jQuery function like so...
$(function myFunction() {
...
});
What i mean is why wrap the function in $
I think that you mean like this:
$(function() {
...
});
This is shorthand for:
$(document).ready(function() {
...
});
What it does is registering a handler for the ready
event, so the code in the function will be run as soon as the document has loaded.
It actually happens to be a short-hand for the following syntax:
function handleDocumentReady ()
{ // handleDocumentReady ()
// Code to handle initialization goes here...
} // handleDocumentReady ()
$(document).ready (handleDocumentReady);