Skip to content
Related Articles

Related Articles

How to run a code on document ready event in jQuery ?

View Discussion
Improve Article
Save Article
  • Last Updated : 24 Mar, 2021

In this article, we will see how to run a code when page load using jQuery. To run a code at page load time, we will use ready() method. This method helps to load the whole page then execute the rest code. This method specifies the function to execute when the DOM is fully loaded.



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.



<!DOCTYpe html>
        How to run a code on document
        ready event in jQuery?
    <script src=
    <!-- jQuery code to show the working of this method -->
        $(document).ready(function () {
            $("body").css("text-align", "center");
            $("h1").css("color", "green");
            $("p").css("font-size", "14px");
            $("p").css("font-weight", "bold");
        How to run a code on document
        ready event in jQuery?
    <p>GeeksforGeeks: A computer science portal</p>


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!