jQuery document ready event
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Executing a Function when Document is Ready in jQuery</title> <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <script> $(document).ready(function(){ // Code to be executed document.getElementById("demo").innerHTML = "Hello World!"; });/*from w w w.j a v a 2 s . c o m*/ </script> </head> <body> <p id="demo"></p> <!--Contents will be inserted here--> </body> </html>