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 trial

JavaScript AJAX Basics (retiring) AJAX and APIs Adding jQuery

$(document).ready() vs. $document.ready()

What is the difference between $(document).ready() vs. $document.ready()? How come $document.ready() throws an error this time?

1 Answer

Steven Parker
Steven Parker
231,269 Points

You probably have not defined $document.

When you use "$(document).ready()", you convert the document element into a jQuery object and then call the ready method on it. That's a typical use case. In fact, it's so common that they have made it so "$(document.ready(your_handler)" can be abbreviated to just "$(your_handler)".

But if you use "$document.ready()", you are calling the ready method on a variable named $document which will not exist unless you have created it previously.