Reputation: 5533
Is
$(document).ready(function(){});
the same as
$(function(){});
?
I believe it is, actually I'm 99% sure it is but wanted a 'second' opinion
Upvotes: 11
Views: 4358
Reputation: 2886
Yes
"the document-ready
idiom is so common, in fact that there's a shortcut version of it... The expanded version $(document).ready
is arguably a better example of self-documenting
code; it's much easier to see at a glance exactly what's going on - especially if it's buried in a page of another developers JavaScript!" - Borrowed from - jQuery Novice to Ninja
Upvotes: 5
Reputation: 75650
Yes it is the same.
From the jQuery Docs - http://api.jquery.com/ready/
All three of the following syntaxes are equivalent:
• $(document).ready(handler)
• $().ready(handler) (this is not recommended)
• $(handler)
Upvotes: 11