JavaScript element.dispatchEvent() Method

You are Here:

JavaScript element.dispatchEvent() Method

The element.dispatchEvent() method dispatches the specified event to the current element.

Note: The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

Example

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>

Syntax

element.dispatchEvent(eventObj)

Parameter Values

ValueTypeExplanation
eventObjRequiredAn event object to be dispatched.

Reminder

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