Global and local variable on the event handler function - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Global and local variable on the event handler function

Demo Code

ResultView the demo in separate window

<html lang="en">
   <head></head>
   <body translate="no">   
      <meta charset="utf-8">   
      <img src="https://placehold.it/100x100">   
      <script>
          window.onload = function(event){
var img = document.getElementsByTagName("img"),five;
img[0].onmousedown = function(event) {
                console.log(five);
                five = 5;/*  ww w  .  j  a  v  a 2  s .co  m*/
};

          };

    
      </script>  
   </body>
</html>

Related Tutorials