I am new to JQuery and I see a piece of code in a web page:
$(function() {
//do something...
});
I don't understand the syntax here. Does it define a function? When will it get called? Can I re-use it?
Thanks
That is the short version of jQuerys DOM ready handler. The code inside the function will be called on page load, when the DOMReady event has fired.
It is equivalent to the following which is a little more verbose, but clearer:
$(document).ready(function() {
// code here
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With