jQuery | ready() with Examples

The ready() method is an inbuilt method in jQuery which helps to load the whole page then execute the rest code. This method specify the function to execute when the DOM is fully loaded.

Syntax:

$(document).ready(function)

Parameters: This method accepts single parameter function which is mandatory. It is used to specify the function to run after the document is loaded.

Return Value: This method returns the document after performing the ready() method.
Below example illustrates the ready() method in jQuery:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYpe html>
<html>
    <head>
        <title>The ready Method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function(){
                $("button").click(function(){
                     $("p").css("color", "green");
                     $("p").css("font-size", "40px");
                     $("p").css("font-weight","bold")
                 });
         });
      </script>
      <style>
         div {
             text-align:center;
             width: 60%;
             min-height: 100px;
             padding: 10px;
             border: 2px solid green;
         }
      </style>
   </head>
   <body>
      <div>
         <p>Welcome to</p>
         <p>GeeksforGeeks!</p>
         <!-- click on this button -->
         <button>Click Here!</button>
      </div>
   </body>
</html>

chevron_right


Output:
ready method

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.