Possible Duplicate:
How to make onclick automatically through onload function
So I have the following function which is being called when I click a button. Here is the code:
<a href="#" role="button" onClick="myFunction('parameter')">
How can I call this function as soon as page is loaded? I tried onLoad function but doesn't seem to work.
There are multiple options for onload event.
In HTML
In Javascript
In JQuery
You can use the following code.
You call in myFunction document.ready or just before closing of body tag.
Within document.ready
Live Demo
Before closing body tag
Have you tried this:
See more at: https://developer.mozilla.org/en-US/docs/DOM/window.onload
Put this anywhere on your page, preferably in the
<head>
See https://stackoverflow.com/a/7911809/584192 for more ways of doing it via jQuery.