Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOğulcan Girginc
24,848 Points$(document).ready(function() {}); vs $(function() {});
On the video, Dave uses
$(document).ready(function () {
// Handler for .ready() called.
}); //end ready
However, when I was reading about .ready()
, the documentation says the code above is equivalent to code below.
$(function() {
// Handler for .ready() called.
}); //end ready
Does anyone know if there is a specific reason why we should use $(document).ready(function() {});
but not $(function() {});
?
2 Answers
Oğulcan Girginc
24,848 PointsIf anyone interested, there is a good explanation on W3 School's Invoking a Function as a Function part.
jason chan
31,009 Pointshttps://learn.jquery.com/using-jquery-core/document-ready/
The other is shorthand.
Oğulcan Girginc
24,848 PointsThe question is why shorthand was not preferred? :)