JavaScript document.createEvent() Method

You are Here:

JavaScript document.createEvent() Method

The document.createEvent() method creates an event of the type specified.

The returned object should be first initialized and can then be passed to targetElement.dispatchEvent.


HTML Online Editor
<!DOCTYPE html> <html> <body> <button id="myBtn" onclick="myFunction()">Click Me</button> <p ondblclick="myDblClick()">Double Click Me</p> <script> function myFunction(){ alert("Hello"); } function myDblClick(){ var x = document.createEvent("MouseEvent"); x.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); document.getElementById("myBtn").dispatchEvent(x); } </script> </body> </html>



Parameter Values

typeRequiredA string that represents the type of event to be created.


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author