Create JavaScript Event with attached data - Javascript DOM

Javascript examples for DOM:Event

Description

Create JavaScript Event with attached data

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  2  s.c  o m

var evObj = document.createEvent('HTMLEvents');
document.body.addEventListener('test', function(e){ document.body.innerHTML = (e === evObj); },true);
evObj.initEvent('test', true, true);
document.body.dispatchEvent(evObj); 

    }

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

Related Tutorials