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.
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
document.createEvent(type)
Parameter Values
Value | Type | Explanation |
---|---|---|
type | Required | A string that represents the type of event to be created. |
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.