Fire event with event.dispatchEvent - Javascript DOM

Javascript examples for DOM:Event

Description

Fire event with event.dispatchEvent

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() {/* w  ww  .j  a  v a 2 s  . c o m*/
el = document.getElementById('x');
el.value = 'pancakes';
ev = document.createEvent('Event');
ev.initEvent('change', true, false);
el.dispatchEvent(ev);
    });

      </script> 
   </head> 
   <body> 
      <input type="text" id="x" onchange="console.log('Changed!')">  
   </body>
</html>

Related Tutorials