Access function inside closures using event - Javascript DOM

Javascript examples for DOM:Event

Description

Access function inside closures using event

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  w  w w  .  j a  v  a 2s .  com
(function () {
    document.getElementById('my').addEventListener("click", a);
    var val="test";
    function a(event){
        console.log(val);
        event.preventDefault();
        event.stopPropagation();
    }
})();
    }

      </script> 
   </head> 
   <body> 
      <a href="#" id="my">test</a>  
   </body>
</html>

Related Tutorials