Declare function inside the body tag and window onload event handler - Javascript DOM Event

Javascript examples for DOM Event:onload

Description

Declare function inside the body tag and window onload event handler

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
window.onload = function () {/*from  ww  w. ja va 2 s . com*/
    var f = function(caller) {
        console.log('test');
    };
    var myButton = document.getElementById('myButton');
    myButton.addEventListener('click', function(){
        f(this);
    });
};

      </script> 
   </head> 
   <body> 
      <button id="myButton" type="button">A button</button>  
   </body>
</html>

Related Tutorials