Tutorial

Document Ready in jQuery

While this tutorial has content that we believe is of great benefit to our community, we have not yet tested or edited it to ensure you have an error-free learning experience. It's on our list, and we're working on it! You can help us out by using the "report an issue" button at the bottom of the tutorial.

jQuery provides and easy way to run code only when the DOM is fully loaded and ready:

$( document ).ready(function() {
  // do stuff
});

Shorthand

You can also use this shorthand:

$(function() {
    // do stuff
});

Wait for the entire page

Use window instead of document to wait until the entire page is ready:

$( window ).load(function() {
    // do stuff
});

0 Comments

Creative Commons License