DOM:event.initMouseEvent
From MDC
Contents |
[edit] Summary
Intializes the value of a mouse event once it's been created (normally using document.createEvent method).
[edit] Syntax
event.initMouseEvent(type, canBubble, cancelable, view,
detail, screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey,
button, relatedTarget);
-
type - the string to set the event's type to. Possible types for mouse events include:
click,mousedown,mouseup,mouseover,mousemove,mouseout. -
canBubble - whether or not the event can bubble. Sets the value of event.bubbles.
-
cancelable - whether or not the event's default action can be prevented. Sets the value of event.cancelable.
-
view - the Event's AbstractView. You should pass the window object here. Sets the value of event.view.
-
detail - the Event's mouse click count. Sets the value of event.detail.
-
screenX - the Event's screen x coordinate. Sets the value of event.screenX.
-
screenY - the Event's screen y coordinate. Sets the value of event.screenY.
-
clientX - the Event's client x coordinate. Sets the value of event.clientX.
-
clientY - the Event's client y coordinate. Sets the value of event.clientY.
-
ctrlKey - whether or not control key was depressed during the Event. Sets the value of event.ctrlKey.
-
altKey - whether or not alt key was depressed during the Event. Sets the value of event.altKey.
-
shiftKey - whether or not shift key was depressed during the Event. Sets the value of event.shiftKey.
-
metaKey - whether or not meta key was depressed during the Event. Sets the value of event.metaKey.
-
button - the Event's mouse event.button.
-
relatedTarget - the Event's related EventTarget. Only used with some event types (e.g.
mouseoverandmouseout). In other cases, passnull.
[edit] Example
This example demonstrates simulating a click on a checkbox using DOM methods. You can view the example in action here.
function simulateClick() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var cb = document.getElementById("checkbox");
var canceled = !cb.dispatchEvent(evt);
if(canceled) {
// A handler called preventDefault
alert("canceled");
} else {
// None of the handlers called preventDefault
alert("not canceled");
}
}