Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

document.ready
ready
html
dom
jquery

What is document.ready in jQuery?

Educative Answers Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The HTML Document Object Model (DOM) is the interface in which one can add, delete, or edit objects in an HTML file. When you open an HTML file, the DOM must be loaded to ensure the file is working correctly.

Once your DOM is loaded, i.e. the entire tree of data has been created then you can start adding external elements into the HTML file.

The ready method allows you to wait for the DOM to be loaded before you add other elements to your HTML file.

How to use the ready method

The ready method is called on the document in the following way:

$(document).ready(function);

Note: Post jQuery 3.0, this way of calling the ready function is not advisable. Rather you simply call the function as $(function) as the ready method is only called on the current document.

Ready method value

Using this method allows time for your DOM to be loaded completely, and then it adds all other elements.

Also, this is a space where you can fire all other events that you need. Within the ready method you can call any events which will be executed in chronological order.

Display "DOM is loading" before the ready event is fired
1 of 3

Example

  • HTML
  • CSS
  • JavaScript

RELATED TAGS

document.ready
ready
html
dom
jquery
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring