---
title: "ready() function do in jQuery with suitable example."  
description: "ready() function do in jQuery with suitable example."  
author: "Ethan Karla"  
published: 2021-07-28  
updated: 2023-11-27  
canonical: https://www.mindstick.com/forum/156650/ready-function-do-in-jquery-with-suitable-example  
category: "jquery"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# ready() function do in jQuery with suitable example.

What does the ready() [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) do in jQuery? [Explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) it by [giving](https://yourviews.mindstick.com/view/80639/regifting-is-far-better-than-giving-away-a-bouquet) suitable example.

## Replies

### Reply by Aryan Kumar

In jQuery, the **$(document).ready()** function is used to execute code when the DOM (Document Object Model) is fully loaded and ready to be manipulated. It ensures that your jQuery code runs after the HTML document has been parsed and is ready for interaction.

Here's an example to illustrate the use of **$(document).ready()**:

```plaintext
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>jQuery Ready Function Example</title>
  <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
</head>
<body>

<!-- Your HTML content -->

<script>
  // This code will run when the DOM is fully loaded and ready
  $(document).ready(function () {
    // Your jQuery code goes here

    // Example: Change the text of an element
    $('#exampleElement').text('DOM is ready!');

    // Example: Attach a click event handler to a button
    $('#exampleButton').click(function () {
      alert('Button clicked!');
    });
  });
</script>

<!-- Your HTML content -->

</body>
</html>
```

In this example:

- The jQuery library is included in the **<head>** section.
- Inside the **<body>** section, there's a **<script>** block that contains your jQuery code.
- The **$(document).ready(function () { ... })** function is used to encapsulate the jQuery code that should run when the DOM is ready.

Inside the **$(document).ready()** function, you can include any jQuery code you want to execute once the DOM is ready. This is a good practice to ensure that your code won't run until the HTML document is fully loaded.

It's worth noting that a shorthand for **$(document).ready()** is **$(function() {...})**. Both notations are equivalent, and you can use either based on your preference.


---

Original Source: https://www.mindstick.com/forum/156650/ready-function-do-in-jquery-with-suitable-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
