views:

57

answers:

2

How do I call a JavaScript function before the end of the body of an HTML page?

+2  A: 
<html>
<head>
<script...>
    function helloWorld() {
        alert('Hello world!');
    }
</script>
</head>
<body>
...some content...
    <script...>
        helloWorld();
    </script>
</body>
</html>
Max
thanks a lot!!!!!!!
Lalchand
+3  A: 

You can just place a <script> block in there, like this:

  <script type="text/javscript">
    myFunction();
  </script>
</body>

Also, if you're using a framework of some sort, most of them have handlers for when the DOM is ready, or you can use window.onload, whatever best fits your situation.

Nick Craver