Example 1 — Create a Basic click
Type alone is enough; numeric fields default to 0.
const event = new MouseEvent("click");
console.log(event.type); // "click"
console.log(event.clientX); // 0
console.log(event.button); // 0
console.log(event instanceof MouseEvent); // true How It Works
- Pass a type.
"click"is case-sensitive. - Defaults apply. Coords and
buttonstart at0. - You get a real instance.
instanceof MouseEventistrue. - Nothing fires yet. Create ≠ dispatch — call
dispatchEventnext.

