How to convert this onclick () function to onload ()
Possible duplicate:
How to make onclick automatically via onload function
So I have the following function called when a button is clicked. Here is the code:
<a href="#" role="button" onClick="myFunction('parameter')">
How can I call this function right after the page is loaded? I tried the onLoad function but doesn't seem to work.
+3
source to share
5 answers
Place this anywhere on your page, preferably in <head>
<script type="text/javascript">
$(function() {
myFunction('parameter');
});
</script>
See fooobar.com/questions/1091347 / ... for more options to do this via jQuery.
+3
source to share
Have you tried this:
window.onload = function(){
myFunction('parameter');
}
See more at: https://developer.mozilla.org/en-US/docs/DOM/window.onload
+2
source to share
You are calling myFunction document.ready or just before the closing body tag.
Inside document.ready
<script type="text/javascript">
$(document).ready(function(){
myFunction('parameter');
});
</script>
Before closing the body tag
<script type="text/javascript">
myFunction('parameter');
</script>
+1
source to share