Reputation: 2524
I see a lot of third party javascript codes that are enclosed with jQuery like this:
$(function() {
// ... javascript code
});
What is the purpose of enclosing with jQuery?
This is different from $(document).ready(function() { /* ... */ });
right?
Upvotes: 2
Views: 320
Reputation: 11733
This is different from
$(document).ready(function() { /* ... */ } );
right?
No, it's only a shorthand. They are exactly the same, as you can read on jQuery's website:
All three of the following syntaxes are equivalent:
$(document).ready(handler)
$().ready(handler)
(this is not recommended)$(handler)
Upvotes: 3