Reputation: 7827
How do I call a JavaScript function before the end of the body of an HTML page?
Upvotes: 0
Views: 3428
Reputation: 630637
You can just place a <script>
block in there, like this:
<script type="text/javascript">
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.
Upvotes: 3
Reputation: 26152
<html>
<head>
<script...>
function helloWorld() {
alert('Hello world!');
}
</script>
</head>
<body>
...some content...
<script...>
helloWorld();
</script>
</body>
</html>
Upvotes: 2