jQuery ready( fn ) Method

« Previous Chapter Next Chapter »

Description:

The ready( fn ) method binds a function to be executed whenever the DOM is ready to be traversed and manipulated.

This method is a replacement for using window.onload

Syntax:

Here is the simple syntax to use this method:

Example

selector.ready( fn )
                                        

Parameters:

Here is the description of all the parameters used by this method:

  • fn: The function to be executed when the DOM is ready.

Example:

Example

<html>
<head>
   <script type="text/javascript"  src="../../js/jquery-2.2.0.js"></script>
   <script type="text/javascript" language="javascript">
   
   $(document).ready(function() {
      $("div").text("The DOM is now loaded...");
   });
   </script>
   <style>
      .div{ margin:10px;padding:12px;
             border:2px solid #666;
             width:200px;
           }
  </style>
</head>
<body>
   <div class="div" style="background-color:blue;"></div>
</body>
</html>
                                        
Code It Online

« Previous Chapter Next Chapter »

Have Any Suggestion? We Are Waiting To Hear from YOU!

Your Query was successfully sent!