JavaScript Example | An Introduction to jQuery $(document).ready()

This function will execute JavaScript code in it after the document is loaded.

<html>

   <head>
      <title>JavaScript Example | An Introduction to jQuery $(document).ready()</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

      <script>
        $(document).ready(function() {
          $("div").click(function() {
            alert("Hello, world!");
          });
        });
      </script>
   </head>
   
   <body>
      <div id = "mydiv">
         Click on this to see a dialogue box.
      </div>
   </body>
</html>